VOOZH about

URL: https://www.geeksforgeeks.org/cpp/cpp-decision-making/

⇱ Decision Making in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Decision Making in C++

Last Updated : 25 Apr, 2026

Decision-making is about conditional execution of a part of the code. In C++, the following decision-making statements are used:

👁 cpp decision making statements

if Statement

In C++, the if statement is the simplest decision-making statement. It allows the execution of a block of code if the given condition is true. The body of the if statement is executed only if the given condition is true.


Output
allowed to vote

Curly braces can be omitted if there is only a single statement inside the if block.


Output
allowed to vote

Flowchart:

👁 Image

2. if-else Statement

The if else is adecision-making statement allows us to make a decision based on the evaluation of a given condition. If the given condition evaluates to true then the code inside the 'if' block is executed and in case the condition is false, the code inside the 'else' block is executed.


Output
number is positive.

Flowchart:

👁 Image


3. if else if Ladder

The if else if Ladder statements allow us to include additional situations after the preliminary if condition. The 'else if' condition is checked only if the above condition is not true, and the `else` is the statement that will be executed if none of the above conditions is true. If a condition is true, only its associated block is executed.


Output
Growing stage

Flowchart:

👁 Image

4. Nested if else

A nested if-else statement contains an 'if' inside another 'if'. It is used to check multiple conditions, and the block of the if whose condition evaluates to true is executed.


Output
positive and even number

Flowchart:

👁 Image

5. Switch Statement

In C++, the switch statement is used when multiple situations need to be evaluated primarily based on the value of a variable or an expression. switch statement acts as an alternative to multiple if statements or if-else ladder and has a cleaner structure and it is easy for handling multiple conditions.


Output
GeeksforGeeks

Flowchart:

👁 Image

6. Ternary Operator ( ? : )

The conditional operator is also known as a ternary operator. It is used to write conditional operations provided by C++. The '?' operator first checks the given condition, if the condition is true then the first expression is executed otherwise the second expression is executed. It is an alternative to an if-else condition in C++.


Output
40

Recommended Links


Comment