#include <stdio.h>
int main() {
int a = -1, b = -10, c = 5;
if (a > b)
printf("Hello World");
else
printf("Get out World");;;;;;
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我为什么第8行仍然有效,有多个分号?
一个空语句是C.法律既然;是语句终止符,多;在语法上是有效的.有时这甚至是有用的:比如for (;;) {/*code here*/}成语.
(虽然有些编译器会在适当的情况下警告你).
请注意,至少在概念上,该;行中的多余部分不是if块的一部分.
您的程序在main函数末尾只有一系列空语句.它被解析为:
#include <stdio.h>
int main() {
int a = -1, b = -10, c = 5;
if (a > b)
printf("Hello World");
else
printf("Get out World");
;
;
;
;
;
}
Run Code Online (Sandbox Code Playgroud)
请注意,int main()应该写入int main(void)并且它应该返回一个int值,例如0.C99使这个return 0;隐含,但它被认为是不好的风格,它实际上不太容易省略它.
| 归档时间: |
|
| 查看次数: |
1125 次 |
| 最近记录: |