C Tricky Question: Print “Hello World” Without Using Any Semicolon In The Program

Unlike a natural language such as English, a formal language such as C adheres to strict code of conduct in which no redundancy, ambiguity or word-play exists. Every statement in C must terminate with a semicolon for it to be syntactically correct. However, the conditional statements such as “if” contains two parts:

  1. Header — where the truth-test of the logical expression is evaluated
  2. Body — statement(s) to be executed should the logical expression evaluates to true (non-zero)

Considering if itself as a micro-function, only its body need to be terminated with semi-colon. Neither its header nor its closing brace should have a semi-colon. This is the key to answer the aforementioned question. Just embed the print statement inside the if’s logical condition and leave its body statement-less.

/*Program to print "Hello World" or any message 
without using any “;” in the program*/

#include <stdio.h>
void main()
    if(printf("Hello World\n"))
    { }



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s