为什么" A + 1"和"&安培A + 1"给出不同的结果,当" A"是一个int数组? [英] Why do "a+1" and "&a+1" give different results when "a" is an int array?

查看:141
本文介绍了为什么" A + 1"和"&安培A + 1"给出不同的结果,当" A"是一个int数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int main()
{
    int a[]={1,2,3,4,5,6,7,8,9,0};

    printf("a = %u , &a = %u\n",a,&a);
    printf("a+1 = %u , &a+1 = %u\n",a+1,&a+1);
}

如何和&放大器;一个是内部间preTED

how a and &a are internally interpreted?

推荐答案

好了,一个是数组的第一个元素的地址,&安培;一个是数组的地址,但显然它们都具有相同的地址

Well, a is the address of the first element of the array, and &a is the address of the array, but obviously they both have the same address.

然而,当添加(或减去)一个号码从一个指针,编译器需要的数据考虑的大小从而在你的情况(假定int的长度是4个字节)一个+ 1将是4比更大因为你移动鼠标指针领先的整数,但和放大器; A + 1将40更大,因为你更提前10整数的指针一个阵列

However when you add (or subtract) a number from a pointer the compiler takes the size of the data into consideration thus in your case (assuming the size of int is 4 bytes) a+1 will be bigger than a by 4 because you move the pointer one integer ahead, but &a+1 would be bigger by 40 because you more the pointer one ARRAY OF 10 INTEGERS ahead.

这篇关于为什么" A + 1"和"&安培A + 1"给出不同的结果,当" A"是一个int数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆