One or two-D arrays
1> initialization
int A[3][3] = {{1,0,0}, {0,1,0}, {0,0,1}}; Here is {}, not ()
2> to treat two-dimensional arrays as one-dimensional arrays
void Print_array (int * p, int row, int line)
{
for (int i=0; i<row; ++i)
{
for (int j=0; j<line; ++j)
{
printf ("%d \ n", * (p + i * row + j)); Equivalent to * (* (p+i) + j); P[I][J]
}
}
}
Call
Print_array (int *) A, 3, 3);
3> Two-dimensional arrays when two-dimensional arrays are used
void Wordsort (char p[][10], int row)
{
Char temp[10];
for (int n=0; n<row; ++n)
{
for (int m=n+1; m<row; ++m)
{
Bubble sort
if (strcmp (P[m], P[n]) < 0)
{
strcpy (temp, p[n]);
strcpy (P[n], p[m]);
strcpy (p[m], temp);
}
}
}
for (int n=0; n<row; ++n)
{
printf ("%s \ n", P[n]);
}
}
Call
Char p[5][10] = {"Hello", "World", "111", "135", "134"};
Wordsort (P, 5);
4> Row pointers (two-dimensional arrays are passed as parameters of a formal parameter)
C + + pointer array, two-dimensional array