2 votes 2 votes main(){ int a[2][3][2]={ { {1,2},{9,8},{3,7} },{ {2,3},{1,4},{5,4} } }; printf("%d %d %d", a[1]-a[0],a[1][0]-a[0][0],a[1][0][0]-a[0][0][0]); } A) 3 3 1 B) 3 6 1 C) 6 6 1 D) 1 1 1 Plz explain komal07 asked Jul 7, 2015 komal07 691 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
3 votes 3 votes a[1][0][0]-a[0][0][0]=2-1=1 a[1][0]-a[0][0]=(address of a[1][0][0]- address of a[0][0][0])/size(int)=6*sizeof(int)/sizeof(int)=6; (note: here a[1][0] is of type int *(i.e, starting address of 1D array or Integer pointer ) hence we divide by sizeof(int) ) a[1]-[0]=(address of a[1]-address of a[0])/ sizeof(int[2])=6*sizeof(int)/sizeof(int[2])=3 (note: here a[1] is of type int (*)[2](i.e, starting address of 2D array or pointer to a Integer array int[2]) hence we divide by sizeof(int [2]) ) Hence the answer is B Mari Ganesh Kumar answered Jul 7, 2015 • edited Jul 7, 2015 by Mari Ganesh Kumar Mari Ganesh Kumar comment Share Follow See all 5 Comments See all 5 5 Comments reply Show 2 previous comments Mari Ganesh Kumar commented Jul 7, 2015 reply Follow Share thanks for correcting me sir.. have edited my answer 0 votes 0 votes komal07 commented Jul 7, 2015 reply Follow Share in the case when a[1] is a pointer to a 3 dimensional array we would divide by 3 to get the difference between 2 pointers? 0 votes 0 votes Mari Ganesh Kumar commented Jul 8, 2015 i edited by Mari Ganesh Kumar Jul 8, 2015 reply Follow Share a has starting address of 3D array or ID array of int [3][2] a[0] has starting address of 2D array or ID array of int[2] a[0][0] has starting address of 1D array or ID array of integers a[0][0][0] is a integer. So a points to a element of sizeof int[3][2] a[0] points to element of sizeof int[2] a[0][0]points to element of sizeof int 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes option D ... bgfbfg answered Jul 18, 2015 bgfbfg comment Share Follow See all 0 reply Please log in or register to add a comment.