【C语言-越界访问】

测试代码如下:很明显for循环的条件<=12不符合数组实际元素的大小

#include <stdio.h>
int main()
{
	int i = 0;
	int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };
	for (i = 0; i <= 12; i++)
	{
		arr[i] = 0;
		printf("hehe\n");
	}
	return 0;
}

程序运行结果:hehe 循环

原因:

 

扫描二维码关注公众号,回复: 16770435 查看本文章

猜你喜欢

转载自blog.csdn.net/ggbb_4/article/details/129397288