C++ Program to execute if statement without any expression


In this program, You will learn how to execute if statement without any expression in C++.


1 = True

0 = False

if( a ){
   //statement
}

Example: How to execute if statement without any expression in C++.

#include<iostream>
using namespace std;

int main() {

    int a;

    cout << "Enter a number:";
    cin >> a;

    if (a) {
        cout << "Welcome";
    } else {
        cout << "Good Bye";
    }

    return 0;
}

Output:

Enter a number:1
Welcome