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++
C++ has many built-in operator types, but the most important
operator types are:
• Arithmetic Operators
• Assignment Operators
• Relational Operators Operators
• Logical Operators

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;

Multiplication: This operator is used to perform multiplication. It is represented by the asterisk or * symbol. Arithmetic
int multiply= numOne*numTwo; Operators
•Division: This operator is used to perform division. It is represented by the forward-slash or / symbol.

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

Assignment
Operators

PAGE 5
Increment and Decrease Operators in C++
The ++ operator

increments the value of the adjacent variable by one;


Int Num;
Num=5;
Increment
Num++; and
the — operator Decreament
decrements the value of the adjacent variable by one Operators
Int Num;
Num=10; in C++
Num--

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;
Cout<<NumTwo;
NumThree=NumThree+1;
Cout<<NumThree;
Increment 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;
a+=b; // can be written as a=a+b Assignment
cout<<a; Operators
b+=a; // can be written as b=b+a
cout<<b;

PAGE 12
Subtract and Assign Operator -=

C++
int a=6, b=10, c=5;
a-=2; // can be written as a=a-2 and result is 4
b-=c; // can be written as b=b-c and result is 5

Multiply and Assign Operator *=


Assignment
Operators
int a=7, b=10, c=5;
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 /=)

C++
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)

(Modulus and Assign Operator %=)


Assignment
Operators
int a=6, b=10, c=8;
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.
Comparison
•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.
Operators
•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