Home >>C++ Tutorial >C++ Operators

C++ Operators

Operators in C++

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:

  • Arithmetic Operators
  • Assignment Operator
  • Relational Operators
  • Logical Operators
  • Unary operator
  • Bitwise Operators
  • Ternary or Conditional Operator
  • Misc Operator
Types Symbol
Arithmetic Operator +,-,/,*,%
Relational Operator <, <=, >, >=,== ,!=
Logical Operator && || !
Bitwise Operator & | << >> ^
Assignment Operator =,+=,-=,*=,/=,%=
Unary Operator ++,--
Ternary Operator(Conditional) ?:

Precedence of Operators in C++

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).

Here is the list of the precedence and associativity of C++operators:

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

No Sidebar ads