Printing “Hello World” without a semicolon in C/C++
Printing “Hello World” is one of the first programs in any programming language. Running this program successfully boosts up the confidence of every beginner and makes them feel like a programmer! Right?
In C/C++ every statement ends with a semicolon. Almost all the statements can be treated as expressions. There are a few ways where we can print a statement without using the semicolon. Those ways to do so are:
- Using if statement
- Using a switch statement
- Using while loop
- Using macros
Following are the examples of printing “Hello World” using these methods.
Using if statement:
This is the code snippet to print “Hello World” using the if statement instead of using a semicolon.
Output: Hello World
Using a switch statement:
This is the code snippet to print “Hello World” using a switch statement instead of using a semicolon.
Output: Hello World
Using while loop:
This is the code snippet to print “Hello World” using while loop instead of using a semicolon.
Output: Hello World
Using Macros:
This is the code snippet to print “Hello World” using macros instead of using a semicolon.
Output: Hello World
#Learntocode Happy Learning!😊