[英]program.exe has stopped working (c)
In case my question is stupid or has already been answered, you'll have to excuse me, since it's the 1st time I am using the forum + when it comes to programming I am still a newbie. 如果我的问题很愚蠢或已经被回答,您必须原谅我,因为这是我第一次使用论坛+在编程方面,我还是一个新手。 I will learn in time.
我会及时学习的。
Anyway, I wrote some lines of code which do not seem to work. 无论如何,我写了一些似乎行不通的代码。 When I am compiling and running the program, a small window pops which says that "myprogram.exe has stopped working" and that windows is checking a solution to the problem.
当我编译并运行程序时,会弹出一个小窗口,上面显示“ myprogram.exe已停止工作”,并且该窗口正在检查问题的解决方案。 If it gives you any clue, I am using codeblocks.
如果有任何线索,我正在使用代码块。
Here is the program: 这是程序:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *ptr,*p;
p=ptr;
ptr="Lineage";
while (*ptr!='\0')
ptr++;
ptr--;
while (ptr>=p)
{
putchar(*ptr);
ptr--;
}
return 0;
}
while (ptr>=p)
p
pointer is uninitalized. p
指针未初始化。 Using uninitialized values leads to UB. 使用未初始化的值将导致UB。
You are assigning ptr
to p
. 您正在将
ptr
分配给p
。 At that point ptr
itself is not pointing to any valid memory location. 此时,
ptr
本身并不指向任何有效的内存位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.