すべてのCプログラムはステートメントで構成されています。プログラムは文ごと文を実行します。それぞれのステートメントは、一般的には、ある表現から成っています。また、式はさらにサブ式を含むことができる。たとえば、次のようになります。
/* diff_statements.c */
#include <stdio.h>
#define SIZE 10 /* SIZE symbolic constant */
int main(void)
{
int index, sum; /* declaration statement */
int boys[SIZE]; /* array declaration */
printf("user enter no of boys in 10 classes...\n");
/* function statement */
for (index = 0; index < SIZE; index++)
scanf("%d", &boys[index]);
/* for statement with single statement */
/* IT'S A GOOD PRACTICE TO REVIEW IF U ENTERED CORRECT VALUES */
printf("No. of boys you entered for 10 classes are as:\n");
for (index = 0; index < SIZE; index++)
printf("%d\t", boys[index]);
printf("\n");
printf("Summing up & Displaying boys in all classes...\n");
/* for statement with block of statements */
for (index = 0; index < SIZE; index++) {
sum += boys[index];
; /* Null Statement; this does nothing here */
}
printf("Total boys in %d classes is %d\n", SIZE, sum);
return 0;
}
すべてのCステートメントは、セミコロン ';'で終了します。表現はしませんが。たとえば:
x + y; /* x + y is an exp but x + y; is a statement. */
5 + 7; /* similarly as above */
while (5 < 10) {
/* 5 < 10 is a relational exp, not a statement. */
/* used as a while test condition */
/* other statements in while loop */
}
result = (float) (x * y)/(u + v);
okey = (x * y)/(u + w) * (z = a + b + c + d);
/* (z = a + b + c + d) is a sub-expression in the above */
/* expression. */
表現は、人間の論理で完全な命令ですが、Cの観点からC.によると、完全な命令は声明ではありません、それは半で終了式の有効な組み合わせであります結腸。
"完全な命令"ではなく、 "完全な命令"です。 「完全な指導」と「表現」は、どの時点で相互に排他的であるという印象を受けましたか? – Cubic
http://stackoverflow.com/questions/3846727/why-is-the-difference-between-an-expression-and-a-statement –
「y = 5」は割り当てです。Cの代入も式であり、右辺の式に評価されます。したがって、「y = 5」は完全な命令(5を「y」に割り当てる)と式(値を「5」とする)の両方である。 –