ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
int n = printf("%d", printf("%s", "abc"));
printf(" %d", n);
  1. A. abc3 4
  2. B. abc3 1
  3. C. abc 3 1
  4. D. 3abc 1

Correct answer: B. abc3 1

The inner call runs first (its result is an argument), printing abc and returning 3. The outer call prints 3 and returns 1, the number of characters it wrote. So the screen shows abc3, then a space and 1.

More C Programming questions

Exams that ask this topic