#include <stdio.h>

int main() {
     /* 연산자 우선 순위
     1. 괄호()
     2. 단항 연산자 ! ++ --
     3. 산술 연산자 * / % -> + -
     4. 비교 연산자 > < >= <= == !=
     5. 논리 연산자 && -> ||
     6. 대입 연산자 = += -=
     */

     // 증감 연산자 ++ --, += -=
     int a = 10;
     printf("a는 %d\n", a);
     a = a + 2;
     printf("a는 %d\n", a);
     a += 2;
     printf("a는 %d\n", a);
     a++; // ++ : 변수에 1을 더해서 다시 저장
     printf("a는 %d\n", a);
     a--; // -- : 변수에 1을 빼서 다시 저장
     printf("a는 %d\n", a);

     int b = 20;
     printf("b는 %d\n", ++b); //전위 1.더하기 1 계산  2.printf
     printf("b는 %d\n", b++); //후위 1.printf  2.더하기 1 계산
     printf("b는 %d\n", b);

     int c = 30;
     printf("c는 %d\n", --c);
     printf("c는 %d\n", c--);
     printf("c는 %d\n", c);

     printf("----문제----\n");
     int x = 4;
     printf("x = %d\n", ++x);
     x = x + 3; // x += 3
     printf("x = %d\n", x++);
     printf("x = %d\n", x);

     int y = 7;
     printf("y = %d\n", ++y);
     printf("y = %d\n", y++);
     printf("y = %d\n", ++y);

     /* 논리 연산자 ! -> && -> ||
     && : AND 모두 참이면 참
     || : OR 하나 이상 참이면 참
     ! : NOT 참과 거짓을 반대로
     ***C언어에서는 참을 1, 거짓을 0로 나타낸다
     */
     a = 5, b = 10, c = 15;
     printf("%d\n", a + b > c && c == 15);
     //               1   2    4    3
     printf("%d\n", a + (b > c));
     //              5  +   0  -> 5

     printf("%d\n", !(a + b <= c) && b != 10);
     //             3   1    2     5    4



     return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: