I have read many posts of pointers and 2d array relation, but I cant seem to understand concept.
Lets say there is a 2d array int a[3][2]
and an array int b[2]
.
now a
is returning a pointer to array of integers of size 3. It would be of type int (*)[2]
.
As my understanding of the concept goes derefrencing it(*a
) would give me the array itself and this decays to a pointer pointing to first element of the 1d array and is of type (int*) . now the bold part is the doubt.
why and how does this decay happen where the array itself(which is the complete 1d array a[0]) decays to first element of the 1d array?
(cant seem to get the why and how part) and cant seem to find it on other links also.
As a[0]
, *a
,&a[0][0]
represent the same pointer. here as a[0] is the first 1d array. then is this true that b
(declared above) and a[0]
represent the same thing (both being 1d array and then decay to the pointer to first element in array of type (int*)?