
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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.
- Related Articles
- Semicolons in C++
- Write a C program to print “ Tutorials Point ” without using a semicolon
- Write a C program to Reverse a string without using a library function
- Write a program to print ‘Tutorials Point’ without using a semicolon in C
- Write a C program to convert uppercase to lowercase letters without using string convert function
- How to write a running C code without main()?
- Write you own Power without using multiplication(*) and division(/) operators in C Program
- Write a C program to print ‘ABCD’ repeatedly without using loop, recursion and any control structure
- Putting semicolons after while and if statements in C++
- Write a Golang program to swap two numbers without using a third variable
- C++ Program to create a function without argument and without a return value
- Write a program to print message without using println() method in java?
- Write program to reverse a String without using reverse() method in Java?
- C program to print a string without any quote in the program
- Write a C program to reverse array

Advertisements