C program to print Hello World without using semicolon

  • Write a program in C to print hello world without using semicolon and using if-else statement.
  • How to print Hello World using switch case statement.

In below programs, we will try to print “Hello World” string without using semicolon.

C program to print Hello World string using if statement

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

Output

Hello World

C program to print Hello World without using semicolon and using switch statement

Here, we are using switch case statement to print “Hello World”. Remember, it is not compulsory to use case statement inside switch, a switch statement without any case value is a valid statement. Check this tutorial on switch statement.

#include<stdio.h>
 
int main(){
    switch(printf("Hello World")){
    }
}

Output

Hello World

C program to print Hello World without using semicolon and using if-else statement

A print statement always returns the number of characters printed on screen. Hence, !printf(“Hello “) will always return a false value which will force evaluation of else-if condition.