What is printed by printf("%d", printf("abc")); in C?
Correct answer
C. abc3, because printf returns the characters written
15 views
C. abc3, because printf returns the characters written
15 views
printf returns the number of characters it successfully wrote, so the inner call prints abc and evaluates to 3, which the outer call then prints as the decimal 3. The visible output is therefore abc3 with no newline. The evaluation order of the two calls is unspecified, but the value is fully computed before the outer call executes, so the count is well defined here.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.