GATE Computer ScienceHardGATE CS (PYQ pattern)

Assume 4-byte int and 8-byte pointers. char s[] = "ab\0cd"; char *p = "ab\0cd"; int a[3][4]; printf("%zu %zu %zu %zu %zu", sizeof(s), sizeof(p), strlen(s), sizeof(a[1]), sizeof(*a) / sizeof(**a)); What is printed?

  1. A. 5 8 2 16 4
  2. B. 6 8 2 16 4
  3. C. 6 8 2 4 4
  4. D. 6 8 5 16 12

Correct answer: B. 6 8 2 16 4

s has 5 characters plus the terminating zero = 6; p is a pointer = 8; strlen stops at the embedded '\0' = 2; a[1] is a row of 4 ints = 16; *a is a row (16 bytes) and **a an int (4), ratio 4.

More Programming and Data Structures (GATE) questions

Exams that ask this topic