# GATE | GATE IT 2006 | Question 51

Which one of the choices given below would be printed when the following program is executed?

 `#include ` `int` `a1[] = {6, 7, 8, 18, 34, 67}; ` `int` `a2[] = {23, 56, 28, 29}; ` `int` `a3[] = {-12, 27, -31}; ` `int` `*x[] = {a1, a2, a3}; ` `void` `print(``int` `*a[]) ` `{ ` `            ``printf``(``"%d,"``, a); ` `            ``printf``(``"%d,"``, *a); ` `            ``printf``(``"%d,"``, *++a); ` `            ``printf``(``"%d,"``, *(++a)); ` `            ``printf``(``"%d\n"``, a[-1][+1]); ` `} ` `main() ` `{ ` `             ``print(x); ` `} `

(A) 8, -12, 7, 23, 8
(B) 8, 8, 7, 23, 7
(C) -12, -12, 27, -31, 23
(D) -12, -12, 27, -31, 56

Explanation:

int `*x[]` = {a1, a2, a3}; line makes x = a1 and likewise. Therefore whenever x is referenced, internally a1 array is being looked upon.

a = a1 = 8

*a = *a3 = a3 = -12

*++a = *(++a) = a1 = 7 : a is now pointing to second element of a1.

*(++a) = *a2 = a2 = 23 : a is now pointing to array a2.

a[-1][+1] = *(a1+1+1) = a1 = 8 : *(a-1) = a1+1 due to last two expressions.

Hence, correct answer would be (A) 8, -12, 7, 23, 8.

This solution is contributed by vineet purswani .

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.