程序:
#include<stdio.h>
int main(void) {
int x[4];
printf("%p\n", x);
printf("%p\n", x + 1);
printf("%p\n", &x);
printf("%p\n", &x + 1);
}
输出:
$ ./a.out
0xbff93510
0xbff93514
0xbff93510
0xbff93520
$
我希望以下是上述程序的输出。例如:
x // 0x100
x+1 // 0x104 Because x is an integer array
&x // 0x100 Address of array
&x+1 // 0x104
但最后一条语句的输出与我预期的不同。 &x
也是数组的地址。所以在这个上增加 1
将打印递增 4 的地址。但是 &x+1
给出递增 10 的地址。为什么?
最佳答案
x -> Points to the first element of the array.
&x ->Points to the entire array.
在这里偶然发现了一个描述性的解释:http://arjunsreedharan.org/post/69303442896/the-difference-between-arr-and-arr-how-to-find
关于c - 取数组地址时指针运算结果不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33775701/