printf function always returns the number of characters printed by the printf function. Let us see this in brief with an example:
main()
{
int a=10;
printf(“%d,printf(“%d %d %d,a,a,a));
}
In this above program the inner printf is first called which prints three times the value of a, with space between each value namely 10 10 10. So 5 characters namely 3 value of a namely 10 and 2 spaces which totals to 5 characters gets printed.
So as explained before the inner printf after printing the values returns the number of characters printed namely 5 which is printed by the outer printf .
The output of the above program is
10 10 10 5
So it is always that function returns a value and so is printf which returns the number of characters successfully printed.
What is the return value from printf() function?
printf function always returns the number of characters printed by the printf function. Let us see this in brief with an example:
In this above program the inner printf is first called which prints three times the value of a, with space between each value namely 10 10 10. So 5 characters namely 3 value of a namely 10 and 2 spaces which totals to 5 characters gets printed.
So as explained before the inner printf after printing the values returns the number of characters printed namely 5 which is printed by the outer printf .
The output of the above program is
So it is always that function returns a value and so is printf which returns the number of characters successfully printed.
Profile Answers by GeekAdmin Questions by GeekAdmin
Questions by GeekAdmin answers by GeekAdmin