I was wondering why the outcome of this program is 5621?
#include <stdio.h>
main()
{
int i=56;
printf("%d\n",printf("%d",printf("%d",i)));
getch();
}
puts() '. It moves the cursor to the next line. Implementation of puts() is easier than printf().
the printf() function is used to print both strings and variables to the screen while the puts() function only permits you to print a string only to your screen.
puts() vs printf() for printing a stringputs() can be preferred for printing a string because it is generally less expensive (implementation of puts() is generally simpler than printf()), and if the string has formatting characters like '%s', then printf() would give unexpected results.
The fprintf() , printf() , and sprintf() functions return the number of characters output, or a negative value if an output error occurs.
printf
returns the amount of characters it has printed.
So first the most inner printf
gets called with 56, printing 56
. Then it returns the amount of characters it has printed (2) to the middle printf
, printing 2
. Then finally the amount of characters printed (1) gets passed into the outer printf
, which then gets printed to procude 5621
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With