Working with multidimensional arrays inside C + +
intarr[2][3] = { {1,2,3}, {4,5,6} };int* P1 = (int*) (arr +1);cout<< p1[0] << Endl;int* P2 = (int*) (&arr +1);cout<< p2[-1] << Endl;cout<< arr << Endl;cout<< &arr << Endl; P1 = (int*) arr[1];cout<< p1[0] << Endl;
Run the above code to debug intermediate process discovery
ARR is an int (*) [3] type, &arr is an int (*) [2][3] type, such as the following example:
int arr[2][3123456 } }; int (*p1)[3] = arr; int (*p2)[2][3] = &arr;
&arr returns the entire array as a pointer
And wrote a small example.
int arr[2][3{ { 1, 2, 3 }{ 4, 5, 6 } }; cout << arr << endl << &arr << endl;
Output Result:
I understand that arr is the array name, the first address of the array store, &arr is the entire array as a variable, so the return address is the first address of the array, is the same, just pointer type, arr is the shaping pointer, &arr is an array pointer.
Array pointer: Pointer to an array with the same size as the array
Array of pointers: one element represents a pointer, the pointer size is the same, and is approximate by the pointer array type.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C + + pointers and arrays