Output of C-language code
June 12, 2012
Output of a C language Program
June 12, 2012

Print 'Hello World' without using semicolon

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).

1 Comment

  1. Print ‘Hello World’ without using semicolon
    [url=http://www.christianlouboutins-outlet.com]christian louboutin outlet[/url]

Leave a Reply to Anonymous Cancel reply

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