독개

#따배씨 1.8 연산자와의 첫만남

by #독개#

 


literal (리터럴)

operand (피연산자)

operator (연산자)

unary (단항)

binary (이항)

ternary (삼항)

 

 

#include <iostream>

using namespace std;

int main()
{
    int x = 2; // x is a variable, 2 is a literal , Assignment is '=' 대입연산자 (우측값을 좌측에 대입)

    cout << "Hello word" << endl; // 문자열 Hello word 도 literal

    cout << 1 + 2 << endl; // literal = 1 , 2 / expression = 1 + 2 / operator = '+'

    //조건 (x > 0)이 참이면 1 , 거짓이면 2
    int y = (x > 0) ? 1 : 2;

    cout << y << endl;


}

 

연산자(operator)

 

x + 1 에서

 

연산자 +

피연산자(operand) x , 1

 

 

대입연산자  = (Assignment)

 

Assignment : 우측값을 좌측에 대입한다

 

a = b ; (b의값을 a에 대입한다)

 

같다의 의미 아니다! 꼭 명심

 

같다는 == 이다

 

 

조건연산자

 

조건 연산자(Conditional oerator)는 C++언어의 유일한 삼항 연산자(Terary operator)입니다.

 

 

 

 

 

 


🐱‍👓독하게 개발

 

블로그의 정보

독한 개발자

#독개#

활동하기