Possible Duplicate:
Why does passing the result of printf to another printf work?
I have a code snippet..
printf("%d", printf("tim"));
The function printf prints the value, tim3 .. The second printf statement does not have a specifier so why do the number of characters get printed along with the string “tim” ?
When i only run this code .. printf("tim"); i get output as, tim Exited: ExitFailure 3 Why does this happen?
And how does the 1st printf statement takes printf("tim") as an argument when it is expecting an integer?
printfprints the string as it is if no format specifier is specified. Soprintf("Hello");will printHelloas it is.You can also do the same by using a format specifier like so –
printf("%s", "Hello");printfalso returns the number of characters printed. Soprintf("Hello");first prints the stringHelloand then returns5.In your statement, you’re printing the return statement of
printfusingprintf("%d", ...);In effect, the statement that you’ve given can be written like this –
As for the failure, I’m guessing you have a
return printf("tim");in yourmainfunction.