Return value of printf() function in C
Ans:
A function always returns a value and printf function returns the number of characters successfully printed.
main()
{
int s=1;
printf("%d",printf("%d %d %d", s,s,s));
}
{
int s=1;
printf("%d",printf("%d %d %d", s,s,s));
}
In this above program the inner printf is first called which prints value of s, three times with space between each value, 1 1 1.
Total 5 characters get printed = 3 values and 2 spaces).
As explained earlier the inner printf after printing the values, returns the number of characters printed, 5 which is printed by the outer printf.
The output of the above program is
1 1 1 5
No comments:
Post a Comment