Similar questions 5 more →
Pointers & Memory
![Question 62, GATE 2015: Assume x address=2000 decimal and unsigned int occupies four bytes. Code: int main(){unsigned int x[4][3]={{1,2,3},{4,5,6},{7,8,9},{10,11,12}};printf("%u, %u, %u",x+3,*(x+3),*(x+2)+3);}. A 2036,2036,2036; B 2012,4,2204; C 2036,10,10; D 2012,4,6.](../../assets/questions/CS-2015-S1-Q62-1.webp)
Answer & solution
Official answer: A
Our answer: A under intended address display; literal printf has undefined behavior
x decays to a pointer to a whole three-element row, so adding 3 advances 3×12 bytes. Dereferencing that pointer produces a row array, which decays to its first-element pointer rather than the value 10. By contrast *(x+2)+3 adds three four-byte elements to the third row's base2024, again yielding numerical address 2036, now one past that row. These address calculations explain intended A only. Printing pointers with %u is a variadic type mismatch and undefined behavior; there is no guaranteed actual C output.
Solution: Each row occupies 3*4=12 bytes. x+3 points to the fourth row at 2000+36=2036; *(x+3) decays to that row’s first element at 2036. *(x+2)+3 is the valid one-past pointer of the third row, also numerically 2036 under the stated layout. Thus the intended address triple is 2036, 2036, 2036, A. However all three arguments are pointers while %u requires unsigned int; this variadic format mismatch is undefined behavior in C. A conforming address display uses %p with each pointer cast to void*, whose textual format is implementation-defined. The omitted stdio declaration is another standalone-code caveat.