An if statement consists of a Boolean expression followed by one or more statements. If the Boolean expression is true, the block of code inside the if statement will be executed else not. This is most simple of all the decision making statements.
The syntax of the if
statement in C++:
1 2 3 4 | if (condition) { //block of statement } |
- If the condition is evaluated true, block of statement is executed.
- If the condition is evaluated false, block of statement is skipped.
if statement Flowchart:

Example of C++ if statement:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <iostream> using namespace std; int main() { int x = 100; //check the Boolean condition if (x < 200) { //if true, following will be displayed cout << "x is less than 200;" << endl; } cout << "value of x: " << x << endl; return 0; } |
Output:
1 2 | x is less than 200; value of x: 100 |