GATE Computer ScienceHardGATE CS (PYQ pattern)

Assume sizeof(int) = 4 and every pointer is 8 bytes. int f(int a[][3], char s[]) { return sizeof(a) + sizeof(*a) + sizeof(s); } int main() { int m[4][3]; char t[] = "gate"; int i = 5; size_t k = sizeof(m[i++]) + sizeof "cs\0e"; printf("%d %zu %d", f(m, t), k, i); } What is printed?

  1. A. 28 17 6
  2. B. 68 17 5
  3. C. 28 15 5
  4. D. 28 17 5

Correct answer: D. 28 17 5

Inside f, a is really int (*)[3] (8 bytes) and *a is a row of 3 ints (12); s is a char * (8): 28. The operand of sizeof is not evaluated (it is not a VLA), so i++ never happens and m[5] is never touched; m[i++] has type int[3], 12 bytes. The literal "cs\0e" occupies 4 characters plus its own terminator = 5 bytes, so k = 17 and i stays 5.

More Programming and Data Structures (GATE) questions

Exams that ask this topic