Operators Dharsh, Thilothama, Samina, Sufi, Suba
Operators Dharsh, Thilothama, Samina, Sufi, Suba
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
if (condition1 || condition2) {
// This block will be executed because condition1 is
true
The logical NOT operator, often represented as "!",
simply negates a boolean value.
if (!condition) {
// This block will be executed because !condition is
true
}
ASSIGNMENT OPERATORS
• 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;