先贴代码

#include <stdio.h>

int main(void)
{
    double a[]={1.1,2.2,3.3};
    unsigned int b,c,d;
    b=&a[0]+1;c=&a[1];d=&a[2];
    printf("diff --  %d", c-b);
    return 0;
}

执行结果是

diff  --  0

这是32位的代码,所以可以用unsigned int类型来储存地址位。

 

由于a[0]是double类型,所以&a[0]+1的返回值是a[0]的地址向后移sizeof(double)个字节。

这样就导致了  &a[0]+1 == a+1 == &a[1] == (void *)a[0]+8  的结果。

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
猜你喜欢
  • 2021-08-23
  • 2022-12-23
  • 2021-05-18
  • 2021-11-21
  • 2022-12-23
  • 2023-01-05
  • 2021-07-29
相关资源
相似解决方案