This chapter takes a long look at C's rich set of operators. We examine more closely the operators we've already introduced, and we introduce the operators we previously ignored. We pay special attention to the operators that have no analog in most other programming languages, such as the shorthand assignment and bit-manipulation operators. Many of C's operators are just similar enough to those of other programming languages to cause problems, so we spend much of our time on their caveats and quirks. The chapter concludes with a case study: a pair of programs that compress and uncompress their input.
Jump to: [Previous Chapter | Next Chapter]
int i, j = 5; i = j++; i = ++j; i���� 5 6 j���� 6 6
expr1 ? expr2 : expr3 // expr1�� TRUE�� expr2, FALSE�� expr3 ����
diff = (x > y) ? (x - y) : (y - x);
~ : Complement
& : AND
| : OR
^ : XOR
<< : Shift left
>> : Shift right
=, op= (+=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=)
, (Comma) sizeof (., ->, &, *) : pointer ���� ������
�켱 ������ ���� ��� associativity�� ���� ����
( ) [ ] . -> |
--> |
Unary operators: ! ~ ++ -- - sizeof * & (type) |
<-- |
* / % |
--> |
+ - |
--> |
<< >> |
--> |
< <= > >= |
--> |
== != |
--> |
& |
--> |
^ |
--> |
| |
--> |
&& |
--> |
|| |
--> |
? : |
<-- |
= += -= *= /= %= &= ^= |= <<= >>= |
<-- |
, | --> |
a = a + b; a += b; a = a - b; a -= b; a = a % b; a %= b;
a = a + 1; a++; a = a - 1; a--;
printf("prompt string"); variable = GetValue();
for (i = 0; i < N; i++) { // N�� �ݺ�. i�� index variable�̶� �� �ݺ� ������ ���� }
while (���ǽ�) { �ݺ� ������ ���� } do { �ݺ� ������ ���� } while (���ǽ�)
if (����) { ������ ���� ��� ������ �� } if (����) { ������ TRUE�� ��� ������ �� } else { ������ FALSE�� ��� ������ �� }
��)
int a, b, c; b = 1; c = -1; // b < c, b != c, b && c, b >= 0 && c <= 0 a = b || c;
����) x�� ������ ��� TRUE�� ���ǽ��� �ۼ��϶�.
(leapyear.c)
(x�� 400�� ����̰ų� 4�� ����̸鼭 100�� ����� �ƴϸ� TRUE)