70,038
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
int main(void)
{
int sum = 0, i = 0;
char input[5];
while (true) //while(1)可以,true不行
{
scanf("%s", input);
for (i = 0; input[i] != '\0'; i++)
{
sum = sum*10 + input[i] - '0';
}
printf("input=%d\n", sum);
}
return 0;
}
test2.c: In function ‘main’:
test2.c:7:9: error: ‘true’ undeclared (first use in this function)
while (true)
^~~~
test2.c:7:9: note: each undeclared identifier is reported only once for each function it appears in
Exited: 256

char a = 'Y';
if(a) //合法
int i = 3;
int *j = &i;
if(j) //合法
0为假,非0为真,在各种C语言考试中这几乎也是一个必考的知识点。
另外,如果你查一下文档,会发现C语言并没有true这个关键字,而C++有。
C关键字:https://msdn.microsoft.com/zh-cn/library/befeaky0.aspx
C++关键字:https://msdn.microsoft.com/zh-cn/library/2e6a4at9.aspx