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 following type of operators:
This chapter will examine the arithmetic, relational, and logical, bitwise, assignment and other
operators one by one.
There are following arithmetic operators supported by C++ language:
Assume variable A holds 10 and variable B holds 20 then:
There are following relational operators supported by C++ language
There are following logical operators supported by C++ language
Assume variable A holds 1 and variable B holds 0 then:
Bitwise operator works on bits and perform bit by bit operation. The truth tables for &, |,
and ^ are as follows:
Assume if A = 60; and B = 13; Now in binary format they will be as follows:
A = 0011 1100
B = 0000 1101
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
The Bitwise operators supported by C++ language is listed in the following table. Assume variable
A holds 60 and variable B holds 13 then:
There are following assignment operators supported by C++ language:
There are few other operators supported by C++ Language.
Operator precedence determines the grouping of terms in an expression. This affects how an
expression is evaluated. Certain operators have higher precedence than others; for example, the
multiplication operator has higher precedence than the addition operator:
For example x = 7 + 3 * 2; Here x is assigned 13, not 20 because operator * has higher precedence
than + so it first get multiplied with 3*2 and then adds into 7.
Here operators with the highest precedence appear at the top of the table, those with the lowest
appear at the bottom. Within an expression, higher precedence operators will be evaluated
Your Query was successfully sent!