The output on most of the systems would be something like:a1.
Now the interesting part is why :
Before any function call is made its arguments are evaluated first. So when the printf is called first its argument would be evaluated which is inturn another function call to printf("%s","a"). The return value of printf("%s","a") would be used as input to the first printf. Now when printf("%s","a") is called it ends up in printing the string a on screen.
The man page of printf tells that the return value of printf would be number of the characeters printed in the screen. So the return value of printf("%s","a") would be 1 which is used as the argument for first printff and eventually gets printed onto the screen.
Now to know why the printf returns the number of characters printed, I would recommed to go and see tha man page of printf.
2006-10-30 06:06:58
·
answer #1
·
answered by Achint Mehta 3
·
1⤊
0⤋
As you may know, printf("%d", var) will output the variable "var" in a decimal format. printf("%s", str) will output the variable "str" as a string.
Additionally, according to Wikipedia: "The printf function returns the number of characters printed, or a negative value if an output error occurred."
Thus, the inner printf call returns the number of characters printed in an integer format, and the outer printf call outputs that integer. Or, in other words, your line of code is printing (in integer format) the output of printing the letter "a" (in string format).
2006-10-30 05:59:01
·
answer #2
·
answered by Danriths V 2
·
0⤊
0⤋