[英]C - runtime error, `malloc(sizeof(int))` causing program to crash
Here is a piece of code: 这是一段代码:
int* linenump;
// ... other stuff
printf("----\n");
linenump = malloc(sizeof(int));
printf("*****\n");
The program only print out ----
then stopped, pop up a window says that the program has stopped, I paste the code in VS then build&run it, no errors, the program works fine. 该程序只打印出
----
然后停止,弹出一个窗口,说该程序已经停止,我将代码粘贴到VS中,然后生成并运行它,没有错误,程序运行正常。
It's a console application. 这是一个控制台应用程序。
So, what I want to know is, in what situation that this will happen? 所以,我想知道的是,在什么情况下会发生这种情况? and how should I solve it?
以及如何解决?
Thanks in advance. 提前致谢。
EDIT: 编辑:
here is the full source code: 这是完整的源代码:
urldown urldown
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.