C - Pointers - Discussion

You Are Here :: Home > C > Pointers - Discussion

 



Q.

#include

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;
}

A. 9 B. 10
C. 11 D. 12

Answer: Option C
Explaination:

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.

*(*(*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.



Discussion

Your Comments Goes here...
NameDiscussion