// Note how pointer arrays and array pointers point to two-dimensional arrays respectively.
# Include <stdio. h>
Main ()
{
Static int M [3] [4] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};/* define a two-dimensional array m and initialize */
INT (* P) [4]; // array pointer P is a pointer pointing to a one-dimensional array. Each one-dimensional array has four int elements.
Int I, J;
Int * Q [3]; // the pointer array Q is an array, the array element is a pointer, and the three int pointers
P = m; // P is a pointer that can direct to a two-dimensional array.
Printf ("-- array pointer output element --/N ");
For (I = 0; I <3; I ++)/* outputs the values of each element in a two-dimensional array */
{
For (j = 0; j <4; j ++)
{
Printf ("% 3d", * (p + I) + j ));
}
Printf ("/N ");
}
Printf ("/N ");
For (I = 0; I <3; I ++, P ++) // P can be viewed as a row pointer.
{
Printf ("% 3d", ** P); // the first element of each row
Printf ("% 3d", * (* p + 1); // the second element of each row
Printf ("% 3d", * (* P + 2); // the third element of each row
Printf ("% 3d", * (* P + 3); // The fourth element of each row
Printf ("/N ");
}
Printf ("/N ");
Printf ("-- pointer array output element --/N ");
For (I = 0; I <3; I ++)
Q [I] = m [I]; // Q is an array, and Q [I] is a pointer.
For (I = 0; I <3; I ++)
{
For (j = 0; j <4; j ++)
{
Printf ("% 3d", Q [I] [J]); // Q [I] [J] can be changed to * (Q [I] + J)
}
Printf ("/N ");
}
Printf ("/N ");
Q [0] = m [0];
For (I = 0; I <3; I ++)
{
For (j = 0; j <4; j ++)
{
Printf ("% 3d", * (Q [0] + J + 4 * I ));
}
Printf ("/N ");
}
Printf ("/N ");
}