쉼표 연산자

MySprtlty·2022년 10월 22일
0

C

목록 보기
31/37

🏷️쉼표 연산자

  • 표준은 쉼표 연산자(Comma Operator)의 피연산자 평가 순서시퀀스 포인트(Sequence Point)를 정의한다.

    1. 좌측 피연산자를 void expression으로 평가한다.
    2. 좌측 피연산자가 평가된 이후 시퀀스 포인트가 존재한다.
    3. 우측 피연산자를 평가한다.
  • 쉼표 연산자의 결과우측 피연산자의 값과 데이터형을 갖는다.

  • 다음은 ISO/IEC 9899 6.5.17에 정의되어 있다.

    The left operand of a comma operator is evaluated as a void expression; there is a sequence point after its evaluation. Then the right operand is evaluated; the result has its type and value. (A comma operator does not yield an lvalue.)

  • 🔍ex)

int x = 0, y = 0, z = 0;
y = (x = 10, z = 20);
printf("%d", y);
  • y의 결과값은 z = 20(우측 피연산자)의 값인 20이 된다.

0개의 댓글