Write a program in C language which does not have even a single semicolon, but prints ‘Hello World‘.

Solution

Semicolon is used to terminate a statement in C language, null statement (Statement that does nothing) can be written in two ways:

;   // Empty or NULL Statement
{}  // Empty of NULL Statement

The below program uses this fact, to print ‘Hello World without having any semicolon in it:

#include
int main()
{
     while( ! printf("Hello World") )
     {
     }
}

Output:

Hello World

Note that printf returns the number of characters printed. In this case ptintf will return 11 (including the space character). 11 in C language is true, NOT of true is false. Hence, control will not enter loop even once (And’Hello World‘ will be printed only once).

One Response

Leave a Reply

Your email address will not be published. Required fields are marked *