Nerd For Tech
Published in

Nerd For Tech

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:

  1. Using if statement

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!😊

--

--

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store