Print Hello World Without Semicolon in C [7 Ways]

We can print Hello World without semicolon in C programming language. There are various ways to do so let’s see the ways.

1. Using if

print “hello world” using if statement and without using semicolon.

// using if
#include <stdio.h>  
int main()    
{    
     if(printf("hello world")){}    
     return 0;  
}  

2. Using switch

print “hello world” using switch statement and without using semicolon.

// using switch
#include <stdio.h>  
int main()    
{    
    switch(printf("hello world")){}    
    return 0;  
}   

3. Using while loop

print “hello world” using while loop and without using semicolon.

// using while loop
#include <stdio.h>  
int main()    
{    
   while(!printf("hello world")){}    
   r
eturn 0;  
}   

Same in for and do while loop

4. Using do-while loop

print “hello world” using do-while loop and without using semicolon.

// using do-while loop
#include <stdio.h>  
int main()    
{    
   do{}
   while(!printf("hello world"));
   return 0;  
}   

5. Using for loop

print “hello world” using for loop and without using semicolon.

// using for loop
#include <stdio.h>  
int main()    
{    
   for(;!printf("hello world"););
   return 0;  
}   

6. Using Macros

print “hello world” using macros and without using semicolon.

// using macros
#include<stdio.h>
#define SHOW printf("Hello World")
int main()
{
  if(SHOW){}
  return 0;
}

In this program, we used macros with the printf() function. Later this macro is used inside if conditional statement. We can also use this macro inside a while, or switch conditional statement.

while(!SHOW){}
switch(SHOW){}
do{}while(!SHOW);
for(;!SHOW;){}

7. Using Command-Line arguments

print “hello world” using command-line arguments and without using semicolon.

// using command line arguments
#include <stdio.h>
int main(int argc, char *argv[printf("Hello World")])
{}

So, these are some ways to print hello world without semicolon in C programming language. If have any other way, let us know in the comment. Share it with your friends.

You may also like,

Support CodeSnail

If you appreciate my work, or if it has helped you along your journey. It would mean a lot to me if you could write a message on my wall and share a cup of coffee (or tea) with me.

Buy Me A Coffee

1 thought on “Print Hello World Without Semicolon in C [7 Ways]”

Leave a Comment

Copy link
Powered by Social Snap