Decision structure in C++
Let there are multiple statements in the code. This program provides an ability to the programmer to decide what statements to
Decision-making is an important concept in any programming language and to accomplish this, C++ uses the following decision
IF statement
IF…ELSE statement
SWITCH statement.
 Сonditional operator (? :)
85.77K
Category: programmingprogramming

Decision structure in C++

1. Decision structure in C++

2. Let there are multiple statements in the code. This program provides an ability to the programmer to decide what statements to

be executed and
what statements should not be executed
depending upon the specific condition. This is
known as
decision making

3. Decision-making is an important concept in any programming language and to accomplish this, C++ uses the following decision

making
statements:
statement
if If
statement
If ...else
statement
if..else
statement
Switch statement
switch statement
Conditional
operator
conditional
operator
Decision
making
statements

4. IF statement

if statement allows us to control a program
whether to execute specific statement or not.
If statement is used to complete an operation, if
a condition is true
Condition can be true or false
The condition will be checked and if it is true
then the statement will be executed.

5. IF…ELSE statement

The if...else executes body of if when the condition is
true and executes the body of else if condition is false.

6. SWITCH statement.

Allows selection among multiple sections of code,
depending on the value of an integral expression.
A switch statement includes one or more switch sections.
Each switch section contains one or more case
labels followed by one or more statements.

7.  Сonditional operator (? :)

Сonditional operator (? :)
The conditional operator (? :) is a ternary operator (it takes three operands).
The first operand is implicitly converted to bool. It is evaluated and all side
effects are completed before continuing.
If the first operand evaluates to true (1), the second operand is evaluated.
If the first operand evaluates to false (0), the third operand is evaluated.
The result of the conditional operator is the result of whichever operand is
evaluated — the second or the third. Only one of the last two operands is
evaluated in a conditional expression.
English     Русский Rules