Professional Documents
Culture Documents
Operators 1
Operators 1
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:
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.
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
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 +=
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
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)
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.
•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