[Solved] nested calls to printf [duplicate]


You may be able to see what’s happening more clearly if you split the statement into several statements:

int temp1 = printf("Hello world!\n");
int temp2 = printf("%d", temp1);
printf("%d", temp2);

The first printf prints Hello world!\n. Since this is 13 characters, it returns 13.

The second printf prints 13. Since this is 2 characters, it returns 2.

The third printf prints 2.

So the full output will be:

Hello world!
132

It would have been more obvious what’s going on if you added more newlines:

printf("%d\n", printf("%d\n",printf("Hello world!\n")));

would print:

Hello world!
13
3

5

solved nested calls to printf [duplicate]