2 C arithmetic operator relational operator equality operator

  • Slides: 52
Download presentation

2 연산자의 종류 C 언어의 연산자 - 산술 - 관계 - 동등 - 논리

2 연산자의 종류 C 언어의 연산자 - 산술 - 관계 - 동등 - 논리 - 비트 - 배정 - 조건 - 증가 - 콤마 - 기타 연산자(arithmetic operator) 연산자(relational operator) 연산자(equality operator) 연산자(logical operator) 연산자(bitwise operator) 연산자(assignment operator) 연산자(conditional operator) , 감소 연산자(increment, decrement operator) 연산자(comma operator) 연산자(cast, sizeof, 포인터 조작 연산자: *, &)

4. 5 비트 단위 연산자 (bit-wise operator) 22 • (예 4. 11) 비트별 논리

4. 5 비트 단위 연산자 (bit-wise operator) 22 • (예 4. 11) 비트별 논리 연산자와 보수연산자의 예 int x, y; x = 33333; y = -77777; [선언 및 배정] 수식 2진수 표현 결과 x y x&y x^y x|y ~ ( x| y) 00000000100000110101 1111111101101000000101111 00000000100000100101 11111111001000011010 1111111101101001000111111 0000000010010110111000000 33333 -77777 32805 -110054 -77249 77248 - 정수형 int의 크기가 32비트라 가정한다. [해 설]

43 4. 13 예 제 1 2 3 4 5 6 7 8 /*

43 4. 13 예 제 1 2 3 4 5 6 7 8 /* File : ex 4 -1. c 정수 710을 우로 4비트 이동 */ #include <stdio. h> int main(void) { int a = 710, b = 4; printf(“%dn”, a >> b); } 예제 4. 1 output 44

48 1 2 3 4 5 6 7 8 9 10 11 12 /*

48 1 2 3 4 5 6 7 8 9 10 11 12 /* File : ex 4 -6. c 18, 35, 21, 96 중에서 최대값을 조건 연산자 이용해 구하는 프로그램 */ #include <stdio. h> int main(void) { int a = 18, b = 35, c = 21, d = 96; int max; max = (a > b) ? a : b; max = (max > c) ? max : c; max = (max > d) ? max : d; printf(“%dn”, max); } 예제 4. 6 - 조건 연산자 ? : 을 사용한다. [해 설] 96 output

49 1 2 3 4 5 6 7 8 9 10 11 /* File

49 1 2 3 4 5 6 7 8 9 10 11 /* File : ex 4 -7. c && 와 || 와 ! 의 사용 #include <stdio. h> int main(void) { int i = 0, j = 0, x, x = i && j; ; printf(“%d %d %dn”, y = !(i || j || x); printf(“%d %d %dn”, } 예 */ 예제 4. 7 y; i, j, x); i, j, y); output 0 0 0 1