for循环的C运行时错误 [英] C runtime error with for loop
本文介绍了for循环的C运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include< stdio.h>
int数组[10];
void main(){
int i; (i = 0; i <10; i ++){
array [i] = i;
。
printf(%i,array [i]);
}
return;
$ b $ p $输出:
运行时错误时间:0内存:2248信号:-1
0123456789
任何帮助将不胜感激,谢谢!
解决方案
int main()
并删除语句 return;
或将其替换为返回0;
将main函数声明为void,并使用没有表达式的return语句会导致程序未定义的行为。
I wrote a small snippit of code that I thought would work, and I am getting all the values displayed in the console but shortly thereafter I am getting an runtime error. Anyone have any idea why?
#include <stdio.h>
int array[10];
void main() {
int i;
for(i = 0; i < 10; i++){
array[i] = i;
printf("%i", array[i]);
}
return;
}
Output:
Runtime error time: 0 memory: 2248 signal:-1
0123456789
Any help would be appreciated, thanks!
解决方案 Declare function main as
int main()
and either remove statement return;
or substitute it for return 0;
Declaring function main as void and using return statement without an expression results in undefined behaviour of the program.
这篇关于for循环的C运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文