LearnFrenzy
Sign in Take a free test

C Input / Output · Predict the Output · Question 2

printf inside printf: what does the return value print? Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int n = printf("C23\n");
    printf("%d\n", printf("Hi "));
    printf("%d\n", n);
    return 0;
}
  • A C23 Hi 3 4 Correct
  • B C23 Hi 2 3
  • C C23 3Hi 4
  • D C23 Hi 3 3
Correct Answer: Option A

printf returns the number of characters written. "C23\n" is 4 characters (the newline counts); the inner call prints "Hi " and returns 3, which the outer call then prints.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links