TheNemesis584 TheNemesis584 - 4 months ago 39
C Question

Strange output from nested printf statemenets

Ok, I'm playing a bit with a code, trying do understand some tricks and how does it work, so I don't understand output of this code

int i = 8;
printf("%d", printf("%o", i));

result of this is 102, I don't know how, I know that 8 in octal system is 10, but what most confuses me is when I put space after
like this

printf("%d", printf("%o ", i));

now, result is 10 3, what is going on here?

Aus Aus

Printf prints to standard out, and returns int, the count of printed characters. So you get:

10 3

which is:

10 is the evaluated inner printf that prints octal 8.

and 3, the evaluated outer printf that prints the "return" value of the inner printf = 3 printed chars.