输出数组成员的成功地址

问题描述 投票:0回答:1

enter image description here

为了更好的理解,我画了这个。在PC的内存中,有连续的存储区,其长度为1个字节(绿色的)。可以将它们分组以表示更大的数据(在我们的示例中为int)。

我想在这张图片中添加的是,绿色方块是成功的地址,例如0x000000,然后是0x000001等。然后,来自arr的地址就象0x000000一样跳了四,而下一个是0x000004(因为在这种情况下,int4bytes。)>

The code_1

int arr[4] = {1,2,3,4};

int *p = arr;

cout << p << endl;
cout << ++p << endl;
cout << ++p << endl;
cout << ++p << endl;

输出_1

0x69fedc
0x69fee0
0x69fee4
0x69fee8

The code_2

char arrr[5] = {'1','2','3','4', '\n'};

char *ptr = arrr;

cout << &ptr << endl;
cout << &(++ptr) << endl;
cout << &(++ptr) << endl;
cout << &(++ptr) << endl;

输出_2

0x69fed0
0x69fed0
0x69fed0
0x69fed0

问题

:我希望在output_2中,我希望地址为0x69fed00x69fed10x69fed20x69fed4

为了更好的理解,我画了这个。在PC的内存中,有连续的存储区,其长度为1个字节(绿色的)。可以将它们分组以表示更大的数据(作为int in ...

c++ arrays memory-address
1个回答
4
投票

这是因为您显示的是指针的地址

© www.soinside.com 2019 - 2024. All rights reserved.