Tuesday, September 20, 2011

Coding Puzzle No. 10?

#include<stdio.h>

char*f="char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c";
 
void main()
{
        printf(f,34,f,34,10);
}
 
 
Output:
char*f="char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c";
main(){printf(f,34,f,34,10);}
[both lines are in the same line in output.]

 
ConCept:
In this line, printf(f,34,f,34,10);  f is replaced by the string. In that string first %c & third %c accounts for 34 i.e. " and %s for whole string, the last %c is for space at the end. Combining all these, results in printing the output.

No comments:

Post a Comment