|
发表于 2021-10-2 23:09:25
|
显示全部楼层
我的意思是这条语句后面没有分号
你加了分号没有错误提示是因为 这样没有语法错误
那个位置可以加分号,只是加了分号不会是你想要的结果
还有,警告算吗?
- $ cat main.c
- #include <stdio.h>
- int main()
- {
- int x = -3, y = 2;
- if(x>y);
- x = -x;
- if(x<y)
- y = -y;
- printf("x=%d,y=%d\n", x, y);
- }
- $ gcc -g -Wall -o main main.c
- main.c: In function ‘main’:
- main.c:6:9: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
- 6 | if(x>y);
- | ^~
- main.c:7:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
- 7 | x = -x;
- | ^
- $
复制代码 |
|