C program to print “Hello” without using semicolon

Solution 1:

Print HELLO with if statement
#include<stdio.h>

void main()
{
    if(printf("hello"))
    {
    }
}

Output:

hello

Explanation:

Here we used ‘printf()’ function to print ‘hello’ on screen. Printf() function returns integer value ie. total number of characters in message, in our example it is 5. So printf() function returns 5 to if statement which will complied as

if(5){
.........
}

If statement operate on true and false condition and here any value other than zero(0) is interpreted as true. So any statements written in body of if statement will also execute. for example:

#include<stdio.h>

void main()
{
    if(printf("hello"))
    {
         if(printf("hi")){}
    }
}

Output:

hellohi

Solution 2:

Print HELLO with while statement
#include<stdio.h>
void main()
{
    while(!printf("Hello"))
    {
    }
}

Solution 3:

Print HELLO with switch statement
#include<stdio.h>
void main()
{
    switch(printf("Hello"))
    {
    }
}