Home
C
C
What is the return value from printf() function?
printf function always returns the number of characters printed. Let us understand this 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 value of a, three times with space between each value, 10 10 10. Total 5 characters get printed (3 value of 10 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
10 10 10 5
A function always returns a value and printf function returns the number of characters successfully printed.
Comments
probably it is taking the value 10 as two characters.then the output ll be 10 10 10 8
i used "t" with every %d in the inner printf,
n i got the output.....
10 10 10 9
dis may b bcoz of the spaces as if we take 1 n 0 as different characters,n count the spaces as well,the total comes out to b 9
1.......1
0.......2
.......3
1.......4
0.......5
.......6
1.......7
0.......8
.......9
n i got the output.....
10 10 10 9
dis may b bcoz of the spaces as if we take 1 n 0 as different characters,n count the spaces as well,the total comes out to b 9
1.......1
0.......2
.......3
1.......4
0.......5
.......6
1.......7
0.......8
.......9
when a was taken as 3 he output is correct,ie.,5. So, you guessed right....
The inner printf will return 8, as it has printed 8 character thrice has it printed a (2*8), as a is two characters wide.and it has printed two spaces as well(between %d %d %d) so total is 8 characters.So the answer comes to be 10 10 108. as first the inner printf executes than the outer one.

but i m getting 10 10 108