我有一个问题,我今天开始学习指针并且出现了一些奇怪的事情:根据我的指南,通过将创建的指针加 1,程序将转到内存中的下一个变量。 当打印 point + 1 的地址时可以看到,但是当我尝试打印 *(point + 1) 的值时,它只打印 d 的地址?
int d = 5;
int e = 12;
int *point = &d;
printf("\n\n%u %i\n%u", point, *point, point + 1);
printf("\n%i", *(point + 1));
为什么会这样? 顺便说一句,我正在使用代码块
最佳答案
int *point = &d;
评估:
*(point + 1)
在 C 中调用未定义的行为。point + 1
不是指向有效对象的指针。
关于c - C 中的指针数学问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21464919/