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[6]; char *s = "ranklao"; printf("%zu %zu %zu", sizeof(a), sizeof(a) / sizeof(*a), sizeof(s)); return 0; }

  1. A. 24 6 8
  2. B. 24 6 7
  3. C. 6 24 8
  4. D. 24 6 4

Correct answer: A. 24 6 8

sizeof(a) = 6×4 = 24; dividing by sizeof(*a)=4 recovers 6; 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