Operators in C++
An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C++ is rich in built-in operators and provides the following types of operators:
1) Arithmetic Operators
2) Relational Operators
3) Logical Operators
4) Bitwise Operators
5) Assignment Operators
6) Misc Operators
This chapter will examine the arithmetic, relational, logical and assignment operators one by one. Others are not needed for beginners......
Arithmetic Operators
There are following arithmetic operators supported by C++ language:
1) Addition (+)
2) Subtraction (-)
3) Multiplication (*)
4) Division (/)
5) Modulus (%)
6) Increment (++)
7) Decrement (--)
They are explained well in the image above.
Relational Operators
There are following are Relational Operators in C++ :-
SUPPOSE A HOLDS VALUE 10 AND B HOLDS 20
1) == - Checks whether value of two operands are equal or not, if yes then it becomes true.
A == B is not true
2) != - Checks whether value of two operands are unequal or not, if yes then it becomes true.
A != B is true
3) < - Checks whether one operand is greater than other or not, if yes then it becomes true.
A < B is true
4) > - Checks whether one operand is greater than other or not, if yes then it becomes true.
A > B is not true
5) >= - Checks whether left operand is greater than or equal to the other or not, if yes then it becomes true.
A >= B is not true
6) <= - Checks whether right operand is greater than or equal to the other or not, if yes then it becomes true.
A <= B is true
Logical Operators
There are following logical operators supported by C++ language
Assume variable A holds 1 and variable B holds 0, then:
1) && - Called logical AND operator. If both the operands satisfy all the given conditions then it becomes true.
A == 1 && B == 0 is true BUT A == 0 && B == 0 is not true
2) || - Called logical OR operator. If both the operands satisfy either of the given conditions then it becomes true.
A == 0 || B == 0 is true.
3) ! - Called logical NOT operator. Use to reverse the logical state of an operand. If a condition is true then it becomes false.
!(A == 1 && B == 1) is true BUT !(A == 1 && B == 0) is not true.
Assignment Operators
There are following assignment operators supported by C++ language:
1) =
2) +=
3) -=
4) *=
5) /=
6) %=
THEY ARE EXPLAINED IN THE IMAGE ABOVE
ABOUT MY NEXT INSTRUCTABLE
I will be posting my next instructable on CONDITIONAL STATEMENTS probably by tomorrow.....
Please like and share my instructable and support me friends...... THANK YOU