我正在考虑以下代码段的结果如何0xc
?不应该是c0-90=30
吗?我在ideone.com上运行它。
#include <stdio.h>
int main(void) {
int a[10] = {0};
int b[10] = {0};
printf("sizeof(a) = %d\n", (int)sizeof(a));
printf("%p, %p\n", (void *)(a+10), (void *)(b+10));
printf("a = %p; b = %p\n", (void *)a, (void *)b);
printf("a-b = %p", (void *)(a-b));
return 0;
}
结果:
sizeof(a) = 40
0x7ffcabb73ce8, 0x7ffcabb73cb8
a = 0x7ffcabb73cc0; b = 0x7ffcabb73c90
a-b = 0xc
答案 0 :(得分:2)
减去指针时,您得到的位置差异没有字节差异
因此,您得到0x7ffcabb73cc0
-0x7ffcabb73c90
= 0x30
个字节
将其除以每个整数4个字节,您得到0x0c
整数