0% found this document useful (0 votes)
2 views15 pages

Operators and Decision Control Structure

The document discusses operators and decision control structures in C++, detailing the types of operators including arithmetic, relational, and logical operators. It explains how these operators function in decision-making processes through conditional statements like if, if-else, and nested if-else. Additionally, it provides examples of C++ programs to demonstrate the application of these concepts.

Uploaded by

MMC RADIOLOGY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views15 pages

Operators and Decision Control Structure

The document discusses operators and decision control structures in C++, detailing the types of operators including arithmetic, relational, and logical operators. It explains how these operators function in decision-making processes through conditional statements like if, if-else, and nested if-else. Additionally, it provides examples of C++ programs to demonstrate the application of these concepts.

Uploaded by

MMC RADIOLOGY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 15

Operators and Decision

Control Structure

By
Amjad Khan Khalil
[email protected]
Operators
 Operators are symbols which have
some meaning in programming
languages and which operate on
some operands.
Operators
For example
Op1 = Op2 + Op3

Operands
Types of Operators in C++
 The following are the three main
types of operators used in C++.
 Arithmetic Operators
 Relational Operators
 Logical Operators
Arithmetic Operators
 The following are the arithmetic
operators used for arithmetic
operations
 + used for addition
 - used for subtraction
 * used for multiplication
 / used for division
 % used for remainder
Relational Operators
 The following operators are known as
relational operators
 > greater than
 < less than
 >= greater than or equal
 <= less than or equal
 == equal
The relational operators will find out the true or
false status of a condition and inform the
compiler accordingly.
Logical Operators
The following operators are used for
logical decision and will often
combine two or more conditions
 && logical AND
 || logical OR
 != logical NOT
&& OPERATOR
 All the condition must be true to
show the result
Condition Condition 2 Condition1 && Condition 2
1
True True True
True False False
False True False
False False False
OR OPERATOR
 Only one of the conditions must
be true to show the result
Condition Condition Condition1 OR Condition 2
1 2

True True True


True False True
False True True
False False False
NOT(!=) OPERATOR
 NOT is used to reverse the result of
the condition
 If the condition is true, NOT will

make it FALSE and if the condition


is FALSE, NOT will make it TRUE
Condition NOT(Condition)
True False
False True
Decision Control Structure
 Programs are executed in C++ in
a sequence, but we can control the
execution of C++ program by
using any control mechanism by
which we can compare things and
come to a decision. This involves
using some operations called
conditional statements.
Con’t
 The following are the fundamentals
flow control structures.
 If- statement
 if- else statement
 Nested if-else statement
If-statement
 This statement select a statement or
group of statements for execution if the
condition is true.
 If the condition is false, it will do nothing.

 The general syntax of if-statement is as

under
if(condition)
statement;
In the above syntax “if” is a keyword.
Drawback of If-statement
 The main disadvantage of if-
statement is that, when the
condition is true it will execute a
statement but if the condition is
false it will do nothing.
 To remove this drawback of if-
statement then we use if-else
If-else statement
 The general syntax of if-else statement
is as under
if(condition)
statement1;
else
statement2;
The above syntax tells the compiler that
execute statement1 if the condition is
true and execute statement2 in case
the condition is false
Con’t
 Write down a computer program in C++ to find out
the number entered through the keyboard is Even
or Odd?
 Write down a computer program in C++ to show
that a character entered through keyboard is upper
case or lower case character and convert the upper
case to lower and vice versa?
 Write down a computer program in C++ to accept
the ASCII code as input for all special characters
except English alphabets and display the
corresponding character.

You might also like