0% found this document useful (0 votes)
25 views24 pages

Operators Dharsh, Thilothama, Samina, Sufi, Suba

Uploaded by

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

Operators Dharsh, Thilothama, Samina, Sufi, Suba

Uploaded by

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

OPERATORS

D.Dharshini-11
R.Thilothama-13
H.Sufiya-3
I.F.Samina thahira-16
A.Suba sree-4
OPERATORS IN C++
An operator is a symbol that operates on a value to perform specific
mathematical or logical computations. They form the foundation of any
programming language. In C++, we have built-in operators to provide
the required functionality.

int c = a + b ;
Classified into 6 types
1.Arithmetic Operators
2.Relational Operators
3.Logical Operators
4.Bitwise Operators
5.Assignment Operators
6.Ternary or Conditional Operators
ARITHMETIC OPERATORS
These operators are used to perform arithmetic and
mathematical operations on the operands.
For example:
+ used for addition
- used for subtraction
* used for multiplication
/ used for division
% used for return the division remaind
UNARY BINARY
These operators work with a These operators work
single operand. with two operands
FOR EXAMPLE: FOR EXAMPLE:
increment(++) addition,subtracts
decrement(--) ,multiplies,divides

int a = 5; int a =3;


a++; //return 6 iint b=6;
a-- //return 4 int c=a+b;
//return 9
RELATIONAL OPERATOR

A relational operator is a symbol


or set of symbols used in
programming to compare the
relationship between two values.
• It helps determine whether
one value is greater than, less
than, equal to, or not equal to
another value.
There are 6 types of
relational operators: •Greater than or
•Equal to (==) equal to (>=)
If (a==b){ If (a >= b){
....... ........
} }
•Not equal to (!=)
•Less than or equal
If (a != b){
....... to (<=)
} If (a <= b){
•Greater than (>) .........
If (a > b){
}
........
}
•Less than (<)
If (a < b){
.........
LOGICAL OPERATORS
Logical operators :
Logical operators are used to check whether an expression
is true or false.
By using this logical operator on the variables, the result
will turn out to be boolean value, i.e., true or false.

Types of Logical Operators


Logical AND (&&):
Logical OR (||):
Logical NOT (!):
• Logical AND (&&):The logical AND operator (&&) returns true if
both
operands are true; otherwise, it returns false

• It's often used to check if multiple conditions are simultaneously


true.
bool condition1 = true;
bool condition2 = false;

if (condition1 && condition2) {


// This block won't be executed because condition2 is
false
}
The logical OR operator, represented by "||", is used in
programming to combine two conditions.

It returns true if at least one of the conditions is true.

bool condition1 = true;


bool condition2 = false;

if (condition1 || condition2) {
// This block will be executed because condition1 is
true
The logical NOT operator, often represented as "!",
simply negates a boolean value.

It flips true to false and false to true.

bool condition = false;

if (!condition) {
// This block will be executed because !condition is
true
}
ASSIGNMENT OPERATORS

In C++, assignment operators are symbols


used to assign a value to a variable. They are
binary operators because they require two
operands: the variable to which the value is
assigned (the left-hand side operand) and the
value being assigned (the right-hand side
operand). The basic assignment operator in
C++ is "=", but there are also compound
assignment operators that combine
assignment with arithmetic, bitwise, or other
operations
1.Basic Assignment Operator (=): This operator assigns the
value of the right-hand side expression to the variable on the
left-hand side.
int x = 10;
2.Compound Assignment Operators: These operators combine
assignment with other operators, allowing for concise
expressions.
x += 5; // Equivalent to x = x + 5
x -= 3; // Equivalent to x = x - 3
3.Other compound assignment operators include bitwise
operators:
x &= 5; // Equivalent to x = x & 5
• In binary, 15 is 1111 and 12 is 1100. Performing bitwise AND
operation results in 1100 which is 12 in decimal.
• So, x becomes 12 after this operation

• a: 1100
• b: 1010
• -----------
• result:1000 (which is 8 in decimal).
BITWISE OPERATORS
In C++, bitwise operations manipulate binary representations of numbers at the bit
level. They are performed using symbols like &, |, ^, ~, <<, and >>. These operations
are useful for tasks like setting specific bits, checking flags, or optimizing memory
usage.
4. NOT (~): Flips all the switches. If a
1. AND (&): Compares two rows of
switches. If both switches are on, the switch is on, it becomes off, and vice
result is on; otherwise, it's off. versa.

2. OR (1): Compares two rows of switches. 5. Left Shift (<<): Moves all the
If at least one switch is on, the result is switches to the left by a certain
on; otherwise, it's off. number of positions.

3. XOR (^): Compares two rows of 6. Right Shift (>>): Moves all the
switches. If the switches are different, the switches to the right by a tain
result is on; if they're the same, it's off. number of positions.
result = operand1 & operand2;
result = operand1 | operand2;

result = operand1 ^ operand2;


result = ~operand;
result = operand <<
numPositions;
result = operand >>
numPositions;
THANKYOU
FOR YOUR TIME

You might also like