| 종류 | 연산자 |
|---|---|
| 대입 연산자 | = |
| 산술 연산자 | +, -, *, %, / |
| 관계 연산자 | ==, !=, >, <, <=, >= |
| 논리 연산자 | &&, |
| 증감 연산자 | ++, -- |
| 삼항 연산자 | ?, : |
| 비트 연산자 | !, &, ^, >>, <<, ! |
#include <stdio.h>
int main(void) {
int a, b;
scanf("%d %d", a, b);
printf("%d + %d = %d", a, b, a + b);
printf("%d - %d = %d", a, b, a + b);
printf("%d * %d = %d", a, b, a + b);
printf("%d / %d = %d", a, b, a / b);
printf("%d % %d = %d", a, b, a % b);
return 0;
}
| 연산자 | 설명 |
|---|---|
| \n | 줄 바꾸기 |
| \t | 탭 |
| \\ | 백슬래시 |
| \" | 큰 따옴표 |
| \b | 백 스페이스 |
#include <stdio.h>
int main(void) {
printf("\"A\tB\\C\bD\n");
return 0;
}
| 연산자 | 설명 |
|---|---|
| > | 크다 |
| < | 작다 |
| == | 같다 |
| != | 다르다 |
| >= | 크거나 같다 |
| <= | 작거나 같다 |
| 0 | False(거짓) |
| 1 | True(참) |
#include <stdio.h>
int main(void) {
int a, b;
scanf("%d %d", &a, &b);
printf("%d\n", a > b);
return 0;
}
| 연산자 | 설명 |
|---|---|
| ! | 부정 |
| && | 그리고 |
| || | 또는 |
#include <stdio.h>
int main(void) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
printf("%d\n", !a);
printf("%d\n", a && b);
printf("%d\n", (a > b) && (b > c));
return 0;
}
| 연산자 | 설명 |
|---|---|
| ++(변수) | i의 값을 1 증가시킨 후 증가된 값을 반환 |
| (변수)++ | i의 값을 1 증가시킨 후 증가되기 전의 값을 반환 |
| --(변수) | i의 값을 1 감소시킨 후에 감소된 값을 반환 |
| (변수)-- | i의 값을 1 감소시킨 후 감소되기 전의 값을 반환 |
#include <stdio.h>
int main(void) {
int a = 7;
printf("%d\n", a++); // 7
printf("%d\n", ++a); // 9
return 0;
}
#include <stdio.h>
int main(void) {
int a = 7, b = 7;
printf("%d\n", (a == b) ? 100 : -100); // 100
return 0;
}
| 연산자 | 설명 |
|---|---|
| ~ | 부정 : ~(11000011)2 = (00111100)2 |
| & | 그리고 : (00001101)2 & (00000011)2 = (00000001)2 |
| | | 또는 : (11001100)2 | (00110000)2 = (11111100)2 |
| ^ | 배타적 : (11001111)2 ^ (00000011)2 = (11001100)2 |
| << | 왼쪽 시프트 : (00001111)2 << 3 = (01111000)2 |
| 연산자 | 설명 |
|---|---|
| 1 | ++, -- |
| 2 | !, ~ |
| 3 | *, /, % |
| 4 | +, - |
| 5 | <<, >> |
| 6 | <, <=, >, >= |
| 7 | ==, != |
| 8 | 비트, 논리 연산자 |
| 9 | 삼항 연산자 |
※ 출처: 패스트캠퍼스, 컴퓨터공학 올인원 패키지