c matrix pointer code example
Example 1: accessing elements 2D array using pointers
#include<stdio.h>
int main(void){
int arr[4][4]={{1,2,3,4},{5,6,7,8},{9,0,1,2}};
int *ptr = &arr;
for(int i=0;i<3;i++){
for(int j=0;j<4;j++)
printf("%d ",*((ptr+i*4)+j));
printf("\n");
}
return 0;
}
Example 2: matrix pointer c
array2d[nRows][nCol];
array2d[iRow][jCol] = value1;
bool b = array2d[iRow][jCol] == value1;
*(*(array2d + iRow) + jCol) = value2;
b = *(*(array2d + iRow) + jCol) == value2;
Example 3: use of pointer in multidimensional array
arr[i][j] = baseAddress + [(i x no_of_cols + j) x size_of_data_type]