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

  1. A. 40 10 7
  2. B. 40 10 8
  3. C. 40 10 4
  4. D. 40 4 8

Correct answer: B. 40 10 8

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