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"))
    { }
}

c-no-semicolon-hello-world-output