码迷,mamicode.com
首页 > 其他好文 > 详细

pointer of 2d array and address

时间:2016-08-10 12:41:14      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

1.int a;

(&a) can be used just like a pointer, with no doubt.

2.int a;

cout<<(&a)<<endl;

---------

Programme Run first,output:       0028FDF0;

Programme Run Second,output:    003FFED0;

 

This means that RAM allocates different storage address.

 

 

------------------

output:  003FFE9C

             003FFEA0

This indicates that size of one int cost 4 bytes. 

1 byte consists 8 bits.

 

4.

int arr[5]={1,2,3,4,5};
cout<<arr<<endl;
cout<<arr+1<<endl;//+1 not +1byte address, step +1 is +1 int_size, so +1 is overloading.
int* brr=arr+1;
cout<<brr[3]<<endl;

------------------

output:  003FFE9C

             003FFEA0

This indicates that size of one int cost 4 bytes. 

1 byte consists 8 bits.

+1 not +1byte address, step +1 is +1 int_size, so +1 is overloading.

 

 

5.

int dd[3][2]={1,2,3,4,5,6};
cout<<"&dd="<<&dd<<endl;
cout<<"(&dd)+1="<<(&dd)+1<<endl;

-----------------------------------

&dd=001FFD80;

(&dd)+1=001FFD98 // 24 bytes for one step.

 

6.

int dd[3][2]={1,2,3,4,5,6};
int ddd[3][2]={7,8,9,10,11,12};
cout<<"&dd="<<&dd<<endl;
cout<<"(&dd)+1="<<(&dd)+1<<endl;

cout<<"dd="<<dd<<endl;
cout<<"dd+1="<<dd+1<<endl;

 

--------------------------------

3
2
1
0038F8A0
0038F894
0038F888
0038F86C
0038F870
5
---------------------
&dd=0038F840
(&dd)+1=0038F858 //
dd=0038F840     // the same as above
dd+1=0038F848 // 8bytes jump, which is 2ints jump
请按任意键继续. . .

--------------------------------------------

 

&dd=0038F840 and  dd=0038F840   IS REALLY PUZZLING.

 =====================

 

Conclusion: 

1. Address has on address;

2. Address has a hierachy;

Hierachy means that step size of different address plus jumps different size.

3. Starting Address usually coincides.

 

pointer of 2d array and address

标签:

原文地址:http://www.cnblogs.com/stevenxiu/p/5756188.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!