重新学习c++ day02

来源:互联网 发布:知返小说下载 编辑:程序博客网 时间:2024/05/17 06:58

关于数组的地址的小问题

int main(){    short tell[10];    cout << "tell:" << tell << endl;    cout << "&tell:" << &tell << endl;    cout << "tell + 1" << tell + 1 << endl;    cout << "&tell + 1" << &tell + 1 << endl;    return 0;}

运行结果
正如所看到的那样,
tell 和 tell+1 在内存中相差2字节(short的长度),
而&tell 和 &tell+1 则相差20字节(tell数组的长度)。

tell 是一个short指针,
而&tell是一个指向包含20个元素的short数组的指针(short (*) [20])。

2016.10.02

0 0
原创粉丝点击