0 votes 0 votes main() { int arr[2][3][2] ={{{1,2}{3,4}{5,6}} , {7,8}{9,10},{11,12}}}; printf("%d%d",a[1]-a[0],a[1][0]-a[0][0]}; return 0; } assume int is of 2 bytes A_i_$_h asked Nov 9, 2017 A_i_$_h 586 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 3 votes 3 votes Here we need to understand what a[0] refers to a[0][0] refers to.. a) When we simply mention 'a' , it is the base address of the entire array and hence points to the entire 3-D array.. b) When we write a[0] , it means there is one level of dereferencing , hence we descend to refer to only a 2-D and specifically through a[0] , we refer to 1st 2-D array.. c) When we write a[0][0] , it refers to first 1D array of 1st 2D array.. d) When we write a[0][0][0] , it directly gives the value of the first element of 1st 1D array of 1st 2D array.. Having said that , now a) If we assign say pointer p = a[0][0] and do p++ , this will lead to point to second element of 1st 1D array of 1st 2D array itself..Thus element wise traversal occurs if use the address of a[0][0] i.e. in steps of 1 element at a time. b) If we assign say pointer q = a[0] and do p++ , this will lead to point to second 1D array instead..Hence using a[0] type of address in 3D array will lead to traversal in units of 1D array.. Thus a[1] - a[0] will lead to 3 as a[1] is the base address of second 2D array and a[0] is of first 2D array.And hence to reach 2nd 2D array , we have passed 3 1D arrays of 1st 2D array , thereby giving the result as 3.. On the other hand , a[1][0] - a[0][0] will lead to 6 as here traversal is element wise as mentioned in a) point.. Hence the correct answer should be 36.. Habibkhan answered Nov 9, 2017 selected Nov 9, 2017 by A_i_$_h Habibkhan comment Share Follow See 1 comment See all 1 1 comment reply A_i_$_h commented Nov 9, 2017 reply Follow Share @ habib can u show me the structure of how it is stored i have never understood how a 3D array is stored 0 votes 0 votes Please log in or register to add a comment.