Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to initialize two-dimensional pointer array in C language
How to initialize two-dimensional pointer array in C language
1, initialization method of array pointer:

int(* p)[4];

char a[3][4];

p = a;

p = & ampa[0];

p = a+ 1;

p = & ampa[ 1]; //Both are correct.

p = a[0]; //Error

p = a[ 1]; //error.

2. First of all, pointer P means a pointer to a four-element one-dimensional array, so it is correct to assign the address of a four-element array to pointer P ... because two-dimensional array &; A is actually a row pointer that & A[0] represents the first row of a two-dimensional array, which contains four elements, so it is a pointer to a one-dimensional array with four elements, which is the correct assignment. Similarly, a+ 1 is & as & amp; A[ 1] is equivalent, that is, a row pointer representing the first row of a two-dimensional array. Similarly, a[0] is also wrong, because a[0] refers to the address of the first element in the first row, that is, & A[0][0] only contains one element, not the address of an array, which is wrong.