Saturday, October 8, 2011

Output of C program (printf)

What would be the output of the following C program? (Is it a valid C program?)
#include <stdio.h>
int main()
{
int i=43;
printf("%d\n",printf("%d",printf("%d",i)));
return 0;
}

Output : 4321

Explanation:This will produce output “4321”. The return type of printf is “int” which is the number of characters written to stdout.
printf("%d\n",printf("%d",printf("%d",i)));
printf("%d\n",printf("%d",printf("%d",43))); => 43
printf("%d\n",printf("%d",2)); => 2
printf("%d\n",1); => 1


No comments:

Post a Comment