【发布时间】:2014-08-16 15:59:00
【问题描述】:
我是 C 新手,正在尝试找出指针。我尝试了这个简单的(根据我的)代码并在 GCC 中不断出现分段错误
#include<stdio.h>
int main()
{
char c[50] = "abc";
char h[50];
char *ptr;
printf("abc");
ptr = c;
printf("Address stored in ptr: %p" , ptr);
printf("Value of ptr: %s" , *ptr);
}
我阅读了段错误,发现当我尝试引用不属于我的内存时会发生它们。我在这段代码中在哪里执行此操作?谢谢!
【问题讨论】:
-
提高警告级别。
标签: c gcc segmentation-fault