how to fill 2d arrays using pointers code example
Example 1: c fill 2d array
int disp[2][4] = {
{10, 11, 12, 13},
{14, 15, 16, 17}
};
int disp[2][4] = { 10, 11, 12, 13, 14, 15, 16, 17};
int i, j;
for (i = 0; i < HEIGHT; i++) {
for (j = 0; j < WIDTH; j++) {
disp[i][j] = disp[i][j];
}
}
Example 2: 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;
}