power point presentation on topic in C++ called "OPERATORS"
sj9399037128
28 views
16 slides
May 10, 2024
Slide 1 of 16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
About This Presentation
download it and enjoy.
Size: 508.51 KB
Language: en
Added: May 10, 2024
Slides: 16 pages
Slide Content
Centre for Artificial Intelligence
Madhav Institute of Technology & Science
Submitted to : Submitted by:
Mr. Arun Kumar Yash Jain(0901AI231077)
Promblem Solving
and Programming
<OPERATORS>
{
}
...
OPERATORS
The symbol that are used in C++ programs to form
an expression are known as OPERATORS.C++ has a
rich set of operators including all C language’s
operators and also some new operators. There are
three categories of operators in C++.
These are :
01: Unary Operators
02: Binary Operators
03: Ternary Operators
OPERATORS
The operators thatr operate a single
operand to form an expression are
Unary operators.like ++,--
The operators that operate two or
more operands are Binary operators.
The operators are +,-,*,/,% etc.
The operators that operates minimum or maximum
three operands are Ternary operators. Only one
(?) used as substitute of if-else statement.
01
02
03
Unary Operators
Binary Operators
Ternary Operators
Type of
operators in
C++
< * Arithmetic Operators
* Logical Operators
* Bitwise Operators
* Relational Operators
* Assignment Operators >
}
The operators that helps the programmer in
mathematical calculation are Arithmetic Operators.
Its include (+) for addition , (-) for
subtraction, (/) for division ,(*) for
multiplication etc.
01.
Arthimetic Operators
<example>
2+5= 7
2*7= 14
8/2= 4
8-4= 4
}
..
Program for arthimetic operators
OUTPUT:
Sum: 15
Difference: 5
Product: 50
Quotient: 2
Remainder: 0
#include <iostream>
using namespace std;
int main() {
int num1 = 10, num2 = 5;
int sum = num1 + num2;
cout<< "Sum: " << sum << endl;
int difference = num1 -num2;
cout<< "Difference: " << difference << endl;
int product = num1 * num2;
cout<< "Product: " << product << endl;
int quotient = num1 / num2;
cout<< "Quotient: " << quotient << endl;
int remainder = num1 % num2;
cout<< "Remainder: " << remainder << endl;
return 0;
}
}
..
02.
Logical
Operators
The Operators that help the
programmer to connect (combine)
two or more expression, are
known as Logical Operators.
It include :
01: (&&) logical AND
02: (||) logical OR
03: (!) logical NOT
Program for logical operators
OUTPUT;
x && y: 0
x && z: 1
x || y: 1
y || z: 1
!x: 0
!y: 1
#include <iostream>
using namespace std;
int main() {
bool x = true, y = false, z = true;
// AND operator (&&)
cout<< "x && y: " << (x && y) << endl; // false
cout<< "x && z: " << (x && z) << endl; // true
// OR operator (||)
cout<< "x || y: " << (x || y) << endl; // true
cout<< "y || z: " << (y || z) << endl; // true
// NOT operator (!)
cout<< "!x: " << !x << endl; // false
cout<< "!y: " << !y << endl; // true
return 0;
}
{
}
03
.
Bitwise Operators
(~) bitwise complement
(<<) left shift
(>>) right shift
(&) bitwise AND
(|) bitwise OR
(^) bitwise exclusive Or
The operators which operate a bit level and
allows the programmer to manipulate
individual bits. These are basically used
for testing or shifting bits.
Bitwise operators are:
Program for Bitwise operators
#include <iostream>
using namespace std;
int main(){
int x = 10, y = 7, z = 0;
// Bitwise AND (&)
z = x & y;
cout<< "x & y = " << z << endl;
// Bitwise OR (|)
z = x | y;
cout<< "x | y = " << z << endl;
// Bitwise XOR (^)
z = x ^ y;
cout<< "x ^ y = " << z << endl;
// Bitwise NOT (~)
z = ~x;
cout<< "~x = " << z << endl;
// Left shift (<<)
z = x << 2;
cout<< "x << 2 = " << z << endl;
// Right shift (>>)
z = y >> 1;
cout<< "y >> 1 = " << z << endl;
return 0;
}
OUYPUT:
x & y = 2
x | y = 15
x ^ y = 13
~x = -11
x << 2 = 40
y >> 1 = 3
04.
Relational Operators
Relational operators are used to
compare values and determine their
relationship. They return a Boolean
value of TRUE(1) if the relation is
true, and false(0) if it’s not.
X == yequal to==
X != yNot equal to!=
X > yGreater than>
X < yLess than <
X >= yGreater than or equal to>=
X <= yLess than or equal to<=
Program for relational operators
int num1 = 20, num2 = 15;
// Equality check
if (num1 == num2) {
cout<< num1 << " is equal to " << num2 << endl;
} else {
cout<< num1 << " is not equal to " << num2 << endl;
}
// Greater than check
if (num1 > num2) {
cout<< num1 << " is greater than " << num2 << endl;
}
// Less than check
if (num1 < num2) {
cout<< num1 << " is less than " << num2 << endl;
}
// Greater than or equal to check
if (num1 >= num2) {
cout<< num1 << " is greater than or equal to " << num2 << endl;
}
// Less than or equal to check
if (num1 <= num2) {
cout<< num1 << " is less than or equal to " << num2 << endl;
}
}
..
OUTPUT:
20 is not equal to 15
20 is greater than 15
20 is greater than or
equal to 15
05.
Assignment Operators
{
}
..
Assignment operators are used to assign values to
variables. They store the value on the right side
of the operator into the variable on the left
side.it include :
01. Simple assign (=)
02. Add and assign (+=)
03. Subtract and assign (-=)
04. Multiply and assign (*=)
05. Divide and assign (/=)
06. Modulo assign (%=)
Program for Assignment operators
int x = 10;
int y = 5;
// Simple assignment
cout<< "Original value of x: " << x << endl;
x = 20; // Assign 20 to x
cout<< "After assignment: x = " << x << endl;
// Compound assignment operators
x += 5; // Equivalent to x = x + 5
cout<< "After x += 5: x = " << x << endl;
y -= 2; // Equivalent to y = y -2
cout<< "After y -= 2: y = " << y << endl;
x *= 3; // Equivalent to x = x * 3
cout<< "After x *= 3: x = " << x << endl;
y /= 2; // Equivalent to y = y / 2
cout<< "After y /= 2: y = " << y << endl;
return 0;
}
OUTPUT:
Original value of x: 10
After assignment: x = 20
After x += 5:
x = 25
After y -= 2:
y = 3
After x *= 3:
x = 75
After y /= 2:
y = 1