Operators
Operators
Course
for
Beginners
Operators
By eng.Manar ELsheref
We will cover these skills
• Operators definition
• Operators Types
Outlines
PAGE 2
Definition of Operator
An operator in C++ is a symbol that helps us to perform specific
mathematical and logical computations on operands. In other
words, we can say that an operator operates the operands.
C++ has many built-in operator types, but the most important
operator types are:
• Arithmetic Operators
C++
• Assignment Operators Operator
• Relational Operators
• Logical Operators s
PAGE 3
he C++ arithmetic operators include:
•Modulo: This operator is used to return the remainder of a division. It is represented by the percent
or % symbol.
C++
int NumberOne, NumberTwo;
NumberOne =5;
// value 5 is assigned to variable NumberOne
NumberTwo = NumberOne;
// value of variable a which is 5 is assigned to the variable NumberTwo b
Assignme
nt
Operators
PAGE 5
Increment and Decrease Operators in C++
The ++ operator
the — operator
t
decrements the value of the adjacent variable by one
Int Num; Operators
Num=10;
Num-- in C++
PAGE 6
/Multiplication of one minus of the
entered numbers #include using
namespace std;
int main()
{
int a,b;
cout << "Enter first number: ";
cin >> a;
cout << "Enter second number: ";
cin >> b;
a--;
b++;
cout << "total = " << a+b << endl;
return 0; }
PAGE 7
//Using the increment operator
#include using namespace std;
int main()
{
int a=50;
int b=30;
cout << "a= " << a++ << "\n";
cout << "a= " << a << "\n";
cout << "b= " << ++b <<"\n";
return 0;
}
PAGE 8
PAGE 9
//Using the increment operator
#include using namespace std;
int main()
{
int a=50;
int b=30;
cout << "a= " << a++ << "\n";
cout << "a= " << a << "\n";
cout << "b= " << ++b <<"\n";
return 0;
}
PAGE 10
Increment Operators in C++
Int NumOne=5,NumTwo=10,NumThree=15;
NumOne++;
Cout <<NumOne;
Cout<<++NumOne;
NumTwo+=1;
Increment
Cout<<NumTwo;
NumThree=NumThree+1;
Cout<<NumThree;
and Decrease
Decrease Operators in C++
Operators in
Int NumOne=5,NumTwo=10;
NumOne--; C++
Cout <<NumOne;
Cout<<--NumOne;
NumTwo-=1;
Cout<<NumTwo;
NumThree=NumThree+1;
Cout<<NumThree;
PAGE 11
Addition and Assign Operator +=
C++
a+=2; // can be written as a=a+2
cout<<a;
b+=4; // can be written as b=b+4
cout<<b; Assignme
a+=b; // can be written as a=a+b nt
cout<<a;
b+=a; // can be written as b=b+a
Operators
cout<<b;
PAGE 12
Subtract and Assign Operator -=
PAGE 13
(Divide and Assign Operator /=)
PAGE 14
PAGE 15
Operators used to compare two numeric values or two characters are
known as comparison operators.
C++
Here is a list of the available comparison operators in C++:
•Greater than: Used to test if a value is greater than another value. It
is represented by the > symbol.
PAGE 17
End of Session
Meet you
in
the Next Session PAGE 18