You are on page 1of 18

C++

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:

•Addition: This operator is used to perform addition. It is represented by the + symbol.

int sum= numOne+numTwo;

•Subtraction: This operator is used to perform subtraction. It is represented by the – symbol.

int sub= numOne-numTwo; Arithmeti


c
Multiplication: This operator is used to perform multiplication. It is represented by the asterisk or * symbol.

int multiply= numOne*numTwo; Operator


•Division: This operator is used to perform division. It is represented by the forward-slash or / symbol. s
int Div=numOne/numTwo;

•Modulo: This operator is used to return the remainder of a division. It is represented by the percent
or % symbol.

int Mod=numOne % numTwo;


PAGE 4
(Assign Operator =)

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 

increments the value of the adjacent variable by one;


Int Num; Increment
Num=5;
and
Decreamen
Num++;

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 +=

int a=6, b=10;

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 -=

int a=6, b=10, c=5;


a-=2;
b-=c;
// can be written as a=a-2 and result is 4
// can be written as b=b-c and result is 5
C++
Assignme
Multiply and Assign Operator *= nt
int a=7, b=10, c=5;
Operators
a*=2; // can be written as a=a*2 and result is 14
b*=c; // can be written as b=b*c and result is 50

PAGE 13
(Divide and Assign Operator /=)

int a=18, b=10, c=5;


a/=2; // can be written as a=a/2 and result is 9 (quotient)
b/=c; // can be written as b=b/c and result is 2 (quotient)
C++
Assignme
 (Modulus and Assign Operator %=) nt
int a=6, b=10, c=8;
Operators
a%=2; // can be written as a=a%2 and result is 0 (remainder)
b%=c; // can be written as b=b%c and result is 2 (remainder)

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.

•Less than: Used to test if a value is less than another value. It is


represented by the < symbol.

•Greater than or Equal to: Used to test if a value is either greater


than OR equal to another value. It is represented by the >= symbol.
Compariso
•Less than or Equal to: Used to test if a value is either less than OR
equal to another value. It is represented by the <= symbol.
nOperators
•Equal to: Used to test if a value is equal to another value.
Represented by two equal symbols or ==.

•Not Equal: Used to test if a value is not equal to another value.


Results in true if so. Represented by the !=.
PAGE 16
C++
Logical
Operators

PAGE 17
End of Session
Meet you
in
the Next Session PAGE 18

You might also like