// 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 ");
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.