pointer of 2d array and address

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.

时间: 2025-01-05 06:25:18

pointer of 2d array and address的相关文章

[C++] 2D Array&#39;s memory allocation

2D Array's memory allocation [C++] 2D Array's memory allocation

sklearn中报错ValueError: Expected 2D array, got 1D array instead:

1 from sklearn.linear_model import LinearRegression 2 lr = LinearRegression() 3 print(tr_x.shape,tr_y.shape) 4 lr.fit(tr_x,tr_y) 5 6 7 # 报错 8 (64,) (64,) 9 Traceback (most recent call last): 10 File "F:/Python_Project/sklearn2_2/zong_fu_xi/A_02.py&qu

[CareerCup] 13.10 Allocate a 2D Array 分配一个二维数组

13.10 Write a function in C called my2DAlloc which allocates a two-dimensional array. Minimize the number of calls to malloc and make sure that the memory is accessible by the notation arr[i][j]. 这道题让我们写个C语言函数my2DAlloc用来给一个二维数组分配内存,并且让我们尽可能的少调用malloc

Jan 18 - Spiral Matrix; 2D Array;

代码: public class Solution { public List<Integer> spiralOrder(int[][] matrix) { List<Integer> resultList = new ArrayList<>(); int row = matrix.length; if(row == 0) return resultList; int col = matrix[0].length; if(col == 0) return resultL

Jan 17 - Rotate Image; 2D Array; xPos and yPos;

代码: public class Solution { public void rotate(int[][] matrix) { int n = matrix.length; for(int i = 0; i < n/2; i++){ int num = n-i*2; for(int j = 0; j < num-1; j++){ int temp = matrix[i][i+j]; matrix[i][i+j] = matrix[i+num-1-j][i]; matrix[i+num-1-j

[Algorithm] Print 2-D array in spiral order

The idea to solve the problem is set five variable, first direction, we need to switch direction after we finish printing one row or one column. dir = (dir+1) % 4 Then set four boundry, top, left, right, bottom: let results = [], dir = 0, //0: left -

Go: using a pointer to array

下面的不是指针指向数组,而是指针指向Slice I'm having a little play with google's Go language, and I've run into something which is fairly basic in C but doesn't seem to be covered in the documentation I've seen so far. When I pass a pointer to an array to a function,

Multi-tasking RTOS for microprocessors with limited memory by saving only a single return address per task during context switching

A real-time operating system (RTOS) for use with minimal-memory controllers has a kernel for managing task execution, including context switching, a plurality of defined tasks, individual ones of the tasks having subroutines callable in nested levels

Return array from functions in C++

C++ does not allow to return an entire array as an argument to a function. However, you can return a pointer to an array by specifying the array's name without an index. If you want to return a single-dimension array from a function, you would have t