Home >>C++ Tutorial >C++ Operators
In order to perform various operations certain symbols are used that are known as operators in C++.
Here are the lists of operators in the C++ language that are used to perform different operations:
Types | Symbol |
---|---|
Arithmetic Operator | +,-,/,*,% |
Relational Operator | <, <=, >, >=,== ,!= |
Logical Operator | && || ! |
Bitwise Operator | & | << >> ^ |
Assignment Operator | =,+=,-=,*=,/=,%= |
Unary Operator | ++,-- |
Ternary Operator(Conditional) | ?: |
In order to specify the sequence of evaluation of the operators that which will be first and next, the precedence of operators is used. The direction of the operators that is to be evaluated is specified by the associativity and it can be from right to left or vice versa.
Here is an example of the precedence of the C ++ operator:
int x=2+5*5;
The "x" variable will contain 50 * (multiplicative operator) is evaluated before + (additive operator).
Category | Operator | Associativity |
---|---|---|
Postfix | () [] -> . ++ - - | Left to right |
Multiplicative | * / % | Left to right |
Shift | << >> | Left to right |
Relational | < <= > >= | Left to right |
Bitwise AND | & | Left to right |
Bitwise XOR | ^ | Left to right |
Logical AND | && | Left to right |
Logical OR | || | Left to right |
Comma | , | Left to right |
Unary | + - ! ~ ++ - - (type)* | Right to left |
Additive | Additive | Right to left |
Equality | == != | Right to left |
Bitwise OR | | | Right to left |
Conditional | ?: | Right to left |
Assignment | = += -= *= /= %=>>= <<= &= ^= |= | Right to left |