"A little progress everyday adds up to big results"

Monday, 12 January 2015

A C program without semicolon

C program to display “India” without using ';' anywhere in the program:

                           Before writing this program, we should first understand what printf returns and its prototype. The function declaration of printf is
int printf ( const char *, ... ) ;
                          It takes variable number of arguments, displays the string till a NULL character is found and returns the number of characters printed.

Now, the program:

#include<stdio.h>
void main()
{
    if ( printf ( "India" ) )
    {
    }
}

The printf () returns 5 in this case. Hence, the 'if' condition is true, but, we are not doing anything inside the block of 'if'.

Next time if someone asks you whether you can write a C program without semicolon, reply 'yes'

No comments:

Post a Comment