我坐着,不打扰任何人,写着 helloworld。我正在尝试使用内存指针。 - “如果你看看接下来会发生什么!”并开始放大这个指针。
#include <stdio.h>
#include <stdlib.h>
int main() {
int *ptr = malloc(sizeof(int));
int *new_ptr = ptr;
if (ptr != NULL) {
int i;
for (i=0; i<100000; i++) {
if (*new_ptr != 0) {
printf("%p: %X \n", new_ptr, *new_ptr);
}
new_ptr=new_ptr+1;
}
free(ptr);
}
}
奇怪的是:尽管我将指针增加了 1,但地址却增加了 4。为什么不能在 0x5568ff6382c0 之后有 0x5568ff6382c1。当然我这里有些不明白,请解释一下。