IF Statement Examples in C++


The syntax of an if statement in C++ is − if(boolean_expression) { // statement(s) will execute if the boolean expression is true } If the boolean expression evaluates to true, then the block of code inside the if statement will be executed.

Example Program

Here is the simple program for if statement in C++.

Source Code Example : 1

using namespace std;
int main()
   int num=90;
      cout<<"\nNumber is less than 100"<<endl;
         cout<<"\n Number is greater than 50";
   return 0;
To download raw file Click Here


Number is less than 100
Number is greater than 50

Source Code Example : 2

using namespace std;
int main()
    int a,b;
    cout<<"\nEnter the number :";
    cout<<"\nEnter the another number :";
        cout<<"\nA is greater then B";
    return 0;
To download raw file Click Here


Enter the number :54
Enter the another number :78
A is greater then B

Basic Programs

Flow Control

IF Statement Examples

Switch Case

Goto Statement

Break and Continue

While Loop

Do While Loop

For Loop

Friend Function in C++

String Examples

Array Examples

Structure Examples

Structure & Pointer Examples

Structure & Functions Examples

Enumeration Examples

Template Examples


Inheritance Examples

Hierarchical Inheritance

Hybrid Inheritance

Multilevel Inheritance

Multiple Inheritance

Single Level Inheritance

Class and Objects

Constructor Example

Destructor Example

Operator Overloading Example

Operator and Function Example

List of Programs

Pointer Examples

Memory Management Examples

Pointers and Arrays

Virtual Function Examples

Learn All in Tamil © Designed & Developed By Tutor Joes