"Mastering" a two-dimensional array pointer definition, initialization
Array pointer: Defines a pointer variable that points to the element of a one-dimensional array, a two-dimensional array pointer-to-row pointer that points to each row of a two-dimensional array, storing the first address definition format of the row: data type (*row pointer variable name) [Length of the second dimension of the array]; Initialization of two-dimensional array pointersinta[2][3]; intb[2][2]; floatf1[4][4]; //Suppose I want to define a row pointer to array a//a = &a[0] = &a[0][0] = a[0] int(*p) [3] =A; Use of two-dimensional array pointers* (* (p+i) +j)//is to get each element of a two-dimensional array
1#include <stdio.h>2 3 intMainintargcConst Char*argv[]) {4 inta[3][4]={1,3,5,7,9, One, -, the, -, +, +, at};5 6 //two-dimensional array pointers7 //A two-dimensional array pointer can replace the array name to use8 int(*p) [4] =A;9 Ten for(intI=0; i<3; i++) { One for(intj=0; j<4; J + +) { A //iterating through an array -printf"%d\t", * (* (p+i) +j));//If it is * (* (a+i) +j) can, because it is a constant, the equivalent of the address but you above the int *p=a;14}//This time the following * (* (p+i) +j) will be an error, because for this When P is a variable, you * is the value, the definition of a two-dimensional array pointer should be to solve the problem
15 printf ( " \n " ); 16 } 18 return 0 ; 19 }
1 3 5 7 9 One - the - + + at
<24> "Mastering" two-dimensional array pointers definition, initialization +