pointer representation of 2-d array

can anyone plzz explain how is this representation of 2-d array possblie a[i][j]=*(*(a+i)+j)

plzz explain it using memory representation

Vivek Vikram Singh vivek14 10 Jun 2016 03:48 pm
Ranita Biswas ranita 11 Jun 2016 11:10 am

Just keep two points in mind. First, a 2D array can be thought of as an 1D array of 1D arrays. Second, when you increment (decrement) a pointer, it goes to the next (previous) element; so if you are working with the address, you have to consider the element size as well. That's why in the below figure, a + 3 calculates to be 5108 where a = 5000 (a is an array of 1D arrays, and each element of a is (9*4) = 36 bytes long, and I have considered the original 2D array a[10][9] to be an integer array with each integer taking 4 bytes space in memory). The whole calculation has been done considering row-major order of memory allocation.