ProgrammingVery hardProduct company OA

What is printed?

What is printed?
char src[] = "abc", dst[8];
char *d = dst;
const char *s = src;
while ((*d++ = *s++));
printf("%s %td %td", dst, d - dst, s - src);
  1. A. abc 3 3
  2. B. abc 4 3
  3. C. abc 3 4
  4. D. abc 4 4

Correct answer: D. abc 4 4

Each test copies a character and then checks it, so the '\0' is copied too and ends the loop. Both pointers are incremented on that last copy as well, so each has moved 4 places. '3 3' forgets that the terminator was copied.

More C Programming questions

Exams that ask this topic