
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print Hello World without semicolon in C++
There are multiple ways to write a C++ program without semicolons. Note that doing this is very bad practice and should never be used in real code. This is presented just as informational content. The easiest way to write a C++ Program without Semicolons is using if statements. Almost all statements in C++ can be treated as expressions. So, if we place the statement inside an if statement with a blank pair of parentheses, we don’t have to end it with a semicolon anymore.
Example
#include<iostream> int main() { if (std::cout << "Hello world!") {} }
Output
This will give the output −
Hello World
You can even take inputs, declare variables, define functions, etc this way. For example,
Example
#include<iostream> int main() { if (int N = 1) { if (std::cin >> N) {} if (std::cout << N) {} } }
Output
This will give the output(if you enter a number 21)
21
Using break, continue, goto, and return Statements
- break and continue statements can be avoided by using corresponding conditions in loops.
- goto statement can be avoided by better control flow structuring.
- return statement in a non-void function can be avoided by passing a reference parameter that acts as the return value and should be assigned at the end of the function.
- Related Questions & Answers
- C Program to print “Hello World!” without using a semicolon
- Print “Hello World” in C/C++ without using header files
- Print “Hello World” without using any header file in C
- Python Program to Print Hello world
- How to print a semicolon(;) without using semicolon in C/C++?
- How to print "Hello World!" using Python?
- Print “Hello World” with empty or blank main in C++
- Beginning C# programming with Hello World
- C++ "Hello, World!" Program
- Hello World using Perl.
- Hello World Program in Java
- Hello World in Dart Programming
- Creating Java Hello World Program
- Display hello world using React.js
- First Hello World project in Arduino
Advertisements