Similar questions 5 more →
Pointers & Memory
![Question 21, GATE 2022: Find the output of this ANSI C main body: int x=1,z[2]={10,11}; int *p=NULL; p=&x; *p=10; p=&z[1]; *(&z[0]+1)+=3; printf("%d, %d, %d\n",x,z[0],z[1]); return 0; (stdio.h included). A 1,10,11; B 1,10,14; C 10,14,11; D 10,10,14.](../../assets/questions/CS-2022-Q21-1.webp)
Your answer
Answer & solution
Official answer: D
Initially x=1 and z={10, 11}. Assigning 10 through p=&x changes x to 10. After p points to z[1], the expression *(&z[0]+1) denotes that same second element; adding 3 changes it to 14. z[0] stays 10. The printed values are 10, 10, 14, D.
Pointer reassignment changes what p refers to; it does not copy values between x and z. After *p=10, x remains 10 even after p moves. Array pointer arithmetic advances by one int, so &z[0]+1 is &z[1], not a byte address or z[0].