Pointer to three dimensional array in c programming

Examples of pointers to 3 dimensional array:

int main(){

const array[2][3][3]={0,1,2,3,4,5,6,7,8,9,10,11,12};
int const (*ptr)[2][3][3]=&array;

printf("%d ",*(*(*ptr)[1]+2));

return 0;

Output: 11


In this example:
array [2][3][3]:It is three dimensional array and its content are constant integers.
ptr: It is pointer to such three dimensional array whose content are constant integer.

Pictorial representation:

Note: In the above figure upper part of box represent content and lower part represent memory address. We have assumed arbitrary address.

*(*(*ptr) [1] +2)
=*(*(*&array) [1] +2)
=*(*array [1] +2)
=*(array [1] [0] +2)
=array [1] [0] [2]

I.e. array element at the 1*(3*3) +0(3) + 2=11th position starting from zero which is 11.

Pointer to function
Pointer to array of function
Pointer to array of string
Pointer to structure
pointer to union
Multi level pointer
Pointer to array of pointer to string
Pointer to three dimentional array
Pointer to two dimensional array
Sorting of array using pointer
Pointer to array of array
Pointer to array of union
Pointer to array of structure
Pointer to array of character
Pointer to array of integer
C tutorial

1 comment:

joshapath said...

"1*(3/*row size*/*3/*column size*/)+0(3/*column size*/"