 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Write a C++ Program without Semicolons?
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. 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.
- the 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.
Advertisements
 