Printf MCQ 20 : Return printf as Parameter



Printf Multiple Choice Questions : Return Parameter as Printf


Question : Guess the output of Program

#include<stdio.h>
#include<conio.h>
int func1()
{
return(printf("Hello"));
}
void main()
{
int i;
i = func1();
printf("%d",i);
}

Options :

  1. Compile Error
  2. Run Time Error
  3. Hello
  4. Hello5

[toggle title="Output"]Hello5[/toggle]

Switch to Printf MCQ Home : Click Here


How and Why ?

  1. Printf Returns Length of String Literal i.e String Inside Quotes.
  • Example : printf("Hi"); returns 2
  • In Above Example , Function First Prints “Hello” and then Returns the Length of “Hello”