print matrix pointers c code example

Example 1: use of pointer in multidimensional array

arr[i][j] = *(ptr + (i x no_of_cols + j))

Example 2: use of pointer in multidimensional array

arr[i][j] = baseAddress + [(i x no_of_cols + j) x size_of_data_type]

Example 3: matrix pointer c

/*any type*/ array2d[nRows][nCol];
// normal 2D array accessing
array2d[iRow][jCol] = value1;
bool b = array2d[iRow][jCol] == value1;
// accessing 2D array with pointers
*(*(array2d + iRow) + jCol) = value2;
b = *(*(array2d + iRow) + jCol) == value2;

Tags:

Misc Example