This chapter covers C's rather small set of statements. We present the fine points of the statements we have already used and describe in detail those we have so far overlooked. While doing so, we improve and extend many of the programs we wrote in earlier chapters, and we write new programs to simulate a simple calculator and to print various breakdowns of input characters. The chapter concludes by tying several topics together in a program that prints an octal dump of its input.
Jump to: [Previous Chapter | Next Chapter]
total = 0 ---> = (assignment operator)�� ����� expression.
total = 0; ---> assignment statement
Embedded assignment : (x = 6) + (y = 7)
Multiple assignment : x1 = x2 = x3 = x4 = 0;
Statements
if (a > b) b++; a--; |
if (a > b) { b++; a--; } |
for (i = 1, sum = 0; i <= 10; sum += i, i++) ; i = -10; while (i++) ;
if �� : expression�� TRUE(!= 0)�� statement ����
if (expression) statement;
if-else �� : expression�� ���̸� statement_1 �ƴϸ� statement_2 ����
if (expression) statement_1; else statement_2;
if (expr) statement_1; staement_2; |
if (expr) statement_1; else statement_2; statement_3; |
if (expr_1) if (expr_2) statement_1; else statement_2; |
if-else if-[else] ��
if (expression_1) statement_1; else if (expression_2) statement_2; else if (expression_n) statement_n; else statement;
switch ��
switch (expression) { case v1: statements case v2: statements default: statements }
��) cardrank.c
1) while �ݺ��� - expression�� ���� ���� statement �ݺ� ����
while (expression) statement
2) for �ݺ���
for (expr1; expr2; expr3) statement
expr1; while (expr2) { statement; expr3; }
3) do-while �ݺ��� - statement�� �����ϰ� expression�� TRUE�� ���� statement �ݺ� ����
do statement while (expresseion);
Goto LABEL; : LABEL: statement;
�ǽ�) ������ ǥ ��� ���α��� �ۼ��϶�.
2 3 4 5 6 7 8 9 ----------------------------------- 2 | 4 6 8 3 | 4 | 5 | 6 | 7 | 8 | 9 | 18
���� ��)
���� ������ �Է��Ͻÿ�. 1234 ��� : 4321
���� ��)
0���� 255 ������ ������ �Է��Ͻÿ�. 10 Forward : 00001010 Reverse : 01010000 0���� 255 ������ ������ �Է��Ͻÿ�. 200 Forward : 11001000 Reverse : 00010011
Hint> Byte�� bit pattern�� bit 7, 6, 5, 4, 3, 2, 1, 0 ������ �����Ǿ��� ��� 1 byte memory�� ����ϴ� ���� ch�� bit pattern�� ����Ϸ���
for (i = 0; i < 8; i++) if ((ch & (1 << (7 - i))) != 0) putchar('1'); else putchar('0');