#include <iostream>using namespacestd;//Note how pointer arrays and array pointers point to two-dimensional arrays, respectively.#include <stdio.h>Main () {Static intm[3][4]={0,1,2,3,4,5,6,7,8,9,Ten, One};/*define two-dimensional array m and initialize*/ int(*p) [4];//The array pointer p is a pointer to a one-dimensional array with 4 int elements per one-dimensional array inti,j; int*q[3];//pointer array q is an array, array elements are pointers, 3 int pointersP=m;//P is a pointer that can point directly to a two-dimensional arrayprintf"--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 ("%3d", * (* (p+i) +j));} printf ("\ n"); } printf ("\ n"); for(i=0;i<3; i++,p++)//p can be seen as a row pointer{printf ("%3d", **p);//the first element of each rowprintf"%3d", * (*p+1));//the second element of each rowprintf"%3d", * (*p+2));//the third element of each rowprintf"%3d", * (*p+3));//the fourth element of each rowprintf"\ n"); } printf ("\ n"); printf ("--pointer array output element--\n"); for(i=0;i<3; i++) Q[i]=m[i];//Q is an array, element 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 replaced by * (Q[I]+J)} printf ("\ n"); } printf ("\ n"); printf (""); 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"); }
Output Result:
This code is very well written .....
Pointer array/array pointer