【发布时间】:2019-08-22 20:11:02
【问题描述】:
我试图通过另一个变量手动提供地址,而不是使用&。
#include <stdio.h>
int main()
{
int ab = 99;
int *p;
int f = &ab;
p = f;
printf("%d\n%d\n%d\n%d\n", &ab, p, f, p); // prints same address
printf("%d\n", *p); // By adding this line, gives SEGFAULT
}
./a.out 给:
284008584
284008584
284008584
284008584
Segmentation fault (core dumped)
【问题讨论】:
-
您的编译器有义务发出有关此错误代码的诊断消息。
标签: c pointers memory-address