减去地址我创建了一个三维阵列在3D阵列
a[2][3][2]
现在,当我尝试打印
printf("%d",a[1] - a[0]);
我得到3作为输出。
我的理解是a [1]给出了[1] [0] [0]元素的地址和[0] [0] [0]的地址[0]。设[0] [0] [0]的地址是BA,[1] [0] [0]的地址是BA + 4 * 2 * 3,其中4字节是整数的存储空间数据类型
我期待的结果是6
同样地,我试过
printf("%d",(&a + 1) - &a);
和接收到的输出为1
我要去哪里错了?
编辑1:整个代码
#include<stdio.h>
int main(){
int a[2][3][2] = {{{1,2},{3,4},{5,6}},{{7,8},{9,10},{11,12}}};
printf("%d",a[1]-a[0]);
return 0;
}
[C中的数组地址减法]的可能重复(http://stackoverflow.com/questions/9963708/array-address-subtraction-in-c) –
'printf(“%d”,a [1] - 一个[0]);'---->'printf(“%p”,(void *)(a [1] - a [0]));' – LPs
提供完整的代码,跟随? – LethalProgrammer