GATE Computer ScienceVery hardGATE CS (PYQ pattern)

char src[] = "gate\0cse"; char dst[20]; char *d = dst, *s = src; int n = 0; while ((*d++ = *s++)) n++; printf("%d %zu %zu", n, sizeof(src), strlen(dst)); What is printed?

  1. A. 8 9 4
  2. B. 4 8 4
  3. C. 4 9 4
  4. D. 4 9 8

Correct answer: C. 4 9 4

The loop copies up to and including the first '\0' (after "gate") and stops, so n = 4 (the terminator is copied but not counted). sizeof(src) counts the characters g a t e \0 c s e plus the final implicit \0 = 9, and strlen(dst) = 4.

More Programming and Data Structures (GATE) questions

Exams that ask this topic