C ์ธ์ด์ ์ฐ์ฐ์์ ๋ํด ์์๋ณด๊ฒ ์ต๋๋ค. C ์ธ์ด๋ ๋ค์ํ ์ฐ์ฐ์๋ฅผ ์ ๊ณตํ์ฌ ์ฐ์ , ๋ ผ๋ฆฌ, ๋น๊ต, ๋์ ๋ฑ ๋ค์ํ ์ฐ์ฐ์ ์ํํ ์ ์์ต๋๋ค. ์๋์์ ๋ช ๊ฐ์ง ์ฃผ์ํ ์ฐ์ฐ์๋ฅผ ์ค๋ช ํฉ๋๋ค.
1) ์ฐ์ ์ฐ์ฐ์ (Arithmetic Operators)
+ (๋ํ๊ธฐ)
- (๋นผ๊ธฐ)
* (๊ณฑํ๊ธฐ)
/ (๋๋๊ธฐ)
% (๋๋จธ์ง)
2) ์ฆ๊ฐ ์ฐ์ฐ์ (Increment and Decrement Operators)
3) ๊ด๊ณ ์ฐ์ฐ์ (Relational Operators)
== (๊ฐ์)
!= (๊ฐ์ง ์์)
< (์๋ค)
> (ํฌ๋ค)
<= (์๊ฑฐ๋ ๊ฐ๋ค)
>= (ํฌ๊ฑฐ๋ ๊ฐ๋ค)
4) ๋ ผ๋ฆฌ ์ฐ์ฐ์ (Logical Operators)
&& (๋
ผ๋ฆฌ AND)
|| (๋
ผ๋ฆฌ OR)
! (๋
ผ๋ฆฌ NOT)
5) ๋นํธ ์ฐ์ฐ์ (Bitwise Operators)
x = 5 = 0 0 0 0 0 1 0 1
y = 3 = 0 0 0 0 0 0 1 1
& (๋นํธ AND) : 0 0 0 0 0 0 0 1 = 1 (๋ชจ๋ ๋ค ์ง์ค)
| (๋นํธ OR) : 0 0 0 0 0 1 1 1 = 7 (๋ ์ค์ ํ๋๋ผ๋ ์ง์ค)
^ (๋นํธ XOR) : 0 0 0 0 1 1 0 = 6 (XOR : ๋ ์ค์ ํ๋๋ผ๋ ๊ฑฐ์ง)
#include <stdio.h>
int main() {
int x = 5; // 0101 in binary
int y = 3; // 0011 in binary
int result = x ^ y; // XOR operation
printf("Result: %d\n", result); // Output: 6 (0110 in binary)
return 0;
}
~ (๋นํธ NOT) : 1 1 1 1 1 0 1 0 → 0 0 0 0 0 1 0 1 → + 1 → 0 0 0 0 0 1 1 0 → -6 (์๋ 2์ง์ ๊ฐ์ด ์์)
#include <stdio.h>
int main() {
int a = 5; // 0101 in binary
int result = ~a; // Bitwise NOT operation
printf("Result: %d\n", result); // Output: -6 (11111010 in two's complement binary)
return 0;
}
<< (๋นํธ ์ผ์ชฝ ์ํํธ) : 0 0 0 0 1 0 1 0 = 10
>> (๋นํธ ์ค๋ฅธ์ชฝ ์ํํธ) : 0 0 0 0 0 0 1 0 = 2
6) ์กฐ๊ฑด ์ฐ์ฐ์ (Conditional Operator)
์ฐ์ฐ์ ์ฐ์ ์์
'Programming > C language' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
7 if & switch (2) | 2024.01.23 |
---|---|
6 scanf ํจ์ (feat. format specifiers) (0) | 2024.01.23 |
4 Constant (1) | 2024.01.23 |
3 Variable (0) | 2024.01.22 |
2 Hello world (0) | 2024.01.22 |
๋๊ธ