ProgrammingHardTCS NQT · Infosys · Product Company SDE

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int main(void) { int a[4]; char *s = "ranklao"; printf("%zu %zu %zu", sizeof(a), sizeof(a) / sizeof(*a), sizeof(s)); return 0; }

  1. A. 4 16 8
  2. B. 16 4 8
  3. C. 16 4 7
  4. D. 16 4 4

Correct answer: B. 16 4 8

sizeof(a) = 4×4 = 16; dividing by sizeof(*a)=4 recovers 4; s is a pointer, so sizeof(s) is 8 on a 64-bit platform, not the string length.

More C Programming questions

Exams that ask this topic