The first is a simple one-dimensional array
Defines an array of int arr[5]; ARR is an int type pointer to the first element of the array, arr+1 is a pointer to the int type of the second element of the pointer array, and *arr is the corresponding value in the pointer, which is better understood
int arr[5] = {1, 2, 3, 4, 5};//to define the array printf ("\n%x", *arr);//1 =arr[0]printf ("\n%x", * (arr+1));//2 =arr[1]
To a two-dimensional array this side of the egg pain, looking for a long time to find a word to explain my doubts, and then everything will be solved
Define a two-dimensional array int arr[2][3]
int Arr[2][3] = {{1, 2, 3}, {4, 5, 6}};p rintf ("\n%d", sizeof (* (&arr))),//24printf ("\n%d", sizeof (*arr));//12
The two-dimensional array is divided into rows and columns, which is an array of three columns,
The first is that &arr is a pointer to the entire array, and the corresponding type is int[2][3], so its corresponding value is 24 (four bytes per digit).
The second arr represents the array pointer of the first row, which may require you to move your brain, in the first example one-dimensional array int arr[3], arr defaults to the pointer for the first element, the type is int, and the pointer increments each time the increment =sizeof (the type of data you use)
So the value of Arr+1 is added 4 (because the pointer type of the element corresponding to the one-dimensional array is int,4 bytes), so +1 finds the next element address of the array, and the * address evaluates the value of the pointer address, but the value inside the two-dimensional array is not of type int, but int[3]
, so arr is a pointer to the first row of the two-dimensional array, which corresponds to the value of {x-i} inside, so its size is 12 bytes
And this time we ran a program.
int Arr[2][3] = {{1, 2, 3}, {4, 5, 6}};p rintf ("\n%x", arr);//printf ("\n%x", *arr);//
Found that the two values are the first address of the array, the first is the first row of the array of pointers, so direct printing will print out the first line of the initial address is normal, we can understand
But isn't the second one supposed to print the value of the first line?
It turns out that because the entire row of data does not have an actual meaning, the compiler encounters this situation as a pointer to the NO. 0 element of the row, like the name of a one-dimensional array, when defined or used with sizeof, & to represent the entire array, which in the expression is converted to a pointer to the array No. 0 A pointer to an element. So if we enter **arr, we'll print out the value of the element in the No. 0 column of that row, which is 1.
Collection of array pointers knowledge points