当前位置:网站首页>C语言程序死循环问题解析——变量被修改
C语言程序死循环问题解析——变量被修改
2022-08-05 05:17:00 【Captain林】
在VS(或其他编译器)开发环境下,会有一系列情况导致程序运行错误,下面就由小编来总结一些常见的程序发生死循环的实例吧。
问题
话不多说,直接上图
解释下列程序出现死循环的原因
#include<stdio.h> int main() { int i = 0; int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; for (i = 0; i <= 12; i++) { arr[i] = 0; printf("hello gdut\n"); } return 0; }
解析
1.调试找寻问题
要搞清楚问题所在,我们先要明白问题出在哪里;
首先我们可以知道当arr数组的下标大于10时,已经导致内存溢出,即栈溢出;
通过调试,我们可以得出当arr数组的下标达到12时,变量i的值被修改了;
因此我们可以大概了解到问题所在:数组越界导致栈溢出,数组的储存地址和变量i的储存地址或空间发生了重合,导致arr[12]被修改的同时变量i也随之被更改。
2.问题图解

结语
看到这里,相信老铁们对C语言的死循环问题已经有了更深刻的了解。我是计算机海洋的新进船长Captain_ldx,如果我的文章能对您有帮助的话,麻烦各位观众姥爷们点赞、收藏、关注我吧!如果你对我的文章有任何问题或者意见,欢迎在评论区给我留言。后期重点注释和知识点将持续更新......
边栏推荐
- Redis设计与实现(第二部分):单机数据库的实现
- Tensorflow steps on the pit notes and records various errors and solutions
- 5G中切片网络的核心技术FlexE
- dataframe 常用操作
- 盘点关于发顶会顶刊论文,你需要知道写作上的这些事情!
- 网工必用神器:网络排查工具MTR
- 电子产品量产工具(4)-UI系统实现
- Comparison and summary of Tensorflow2 and Pytorch in terms of basic operations of tensor Tensor
- IT系统运行维护方法及策略
- 6k+ star,面向小白的深度学习代码库!一行代码实现所有Attention机制!
猜你喜欢

【论文阅读-表情捕捉】ExpNet: Landmark-Free, Deep, 3D Facial Expressions

神经网络也能像人类利用外围视觉一样观察图像

Thread handler handle IntentServvice handlerThread

【shell编程】第二章:条件测试语句

A deep learning code base for Xiaobai, one line of code implements 30+ attention mechanisms.
![[Intensive reading of the paper] R-CNN's Bounding box regression problem is detailed](/img/ef/a058ec08bd0a6313e3610a4ebc9685.png)
[Intensive reading of the paper] R-CNN's Bounding box regression problem is detailed

Tensorflow steps on the pit notes and records various errors and solutions

LeetCode刷题之第74题

【Kaggle项目实战记录】一个图片分类项目的步骤和思路分享——以树叶分类为例(用Pytorch)

CVPR最佳论文得主清华黄高团队提出首篇动态网络综述
随机推荐
【Pytorch学习笔记】8.训练类别不均衡数据时,如何使用WeightedRandomSampler(权重采样器)
读论文-Cycle GAN
面向小白的深度学习代码库,一行代码实现30+中attention机制。
【ts】typeScript高阶:any和unknown
LeetCode刷题之第33题
LeetCode刷题之第55题
SQL(1) - Add, delete, modify and search
You should write like this
[Practice 1] Diabetes Genetic Risk Detection Challenge [IFLYTEK Open Platform]
[Pytorch study notes] 11. Take a subset of the Dataset and shuffle the order of the Dataset (using Subset, random_split)
LeetCode刷题之第1024题
1004 成绩排名 (20 分)
Jupyter notebook选择不同的Anaconda环境作为内核运行
LeetCode刷题之第86题
【论文阅读-表情捕捉】High-quality Real Time Facial Capture Based on Single Camera
LeetCode刷题之第129题
OSPF网络类型
framebuffer应用编程及文字显示(2)
三、自动配置源码分析
十一、拦截器运行原理