Jun 122012
 
 C Tags:  Add comments

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 to “Print ‘Hello World’ without using semicolon”

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

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)