Saturday, November 26, 2011

Print your Name without the semicolon in a C program

Okay.. this question used to be quite a favorite at coding championships 4-5 years back. The question seemed tough as all programming books start with the statement that "All statements in ' XYZ ' language end with a ( ; ) semicolon, except for a few conditional, looping and other control structure constructs. Actually the problem lies in the fact that we try to use standalone printf() statements in our solutions.
Here's a solution for it :

main()
{
 if(printf("MY NAME")) {}
 else {}
}

No comments:

Post a Comment