我通常想做的是检查何时(x-3) > i.
我得到以下代码:
int main()
{
int x = 10, i;
for(i = 0; i < 15; i++) {
if(x-3)
printf("%d, ", x);
x--;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不小心写了(x-3)而不是(x-3 > i),我得到了这些结果:
10,9,8,7,6,5,4,2,1,0,-1,-2,-3,-4,
缺少数字3.我明白这是某种与x-3表达方式有关的东西,但我还没有在谷歌找到一个明确的答案.
有没有人有想法?谢谢...
抱歉初学者问题,但我写了这段代码:
#include <stdio.h>
int main()
{
int y = 's';
printf("%c\n", y);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译器(的Visual Studio 2012)不警告我可能数据丢失(比如从int到float).
我在谷歌找不到答案(或没有正确搜索).
我想知道这是否因为int内存中的存储空间是4而且它可以容纳1个内存存储空间char.
我不确定这一点.
提前致谢.
我正在构建一个程序,该程序应该根据小写字母在字符串中查找字符。
#include <stdio.h>
#include <string.h>
int main()
{
char str[];
int i;
for (i = 0; i < strlen(str); i++)
{
if (str[i] < 48 || str[i] > 57)
break;
}
return 0;
Run Code Online (Sandbox Code Playgroud)
}
我以前从未遇到过这个问题,并且我使用了不完整的类型(数组和字符串)数百种情况。
不管怎样,Visual Studio 2012会发出有关不完整类型的警报:
1 IntelliSense: incomplete type is not allowed Visual Studio 2012\Projects\C\C\main.c 6 7 C
Run Code Online (Sandbox Code Playgroud)
怎么了?
所以,我刚研究了Arrays材料并遇到了问题......
我得到了以下代码:
int a[5];
int i;
for(i=0; i<=10; i++) {
scanf("%d", &a[i]);
}
Run Code Online (Sandbox Code Playgroud)
我在一个数组上声明它的长度为5.
然后,我运行了一个for从0到10 的循环,插入数字a[i].
我使用这个表(我创建的)来了解执行期间发生的事情:
你看到红色箭头?这就是她停止循环的地方,因为它们a[]不能获得超过5个值.这意味着,那a[6]不存在.
尽管如此,它一直在询问数字,并不断将它们保存到数组中.
还有一件事,我目前正在使用Dev C++编译器.
有谁知道为什么会这样?
谢谢!