C++ operators are symbols that are used in the C++ program to form an expression.C++ has a large set of operators. It includes all C languages operator and has its own other operators. There are three categories of an operator in C++. They are listed below:
- Unary Operators
- Binary Operators
- Ternary Operators
Unary operators are those operators that operate a single operand to form an expression. There are basically two unary operators.
- +(increment) operator
- -(decrement) operator
Binary operators are those operators that operate two or more operands to form an expression. Some of the binary operators are -,+,/,*,! etc.
Example: x+y,x*y,x-y,x/y etc.
Ternary operators are those operators that operate a minimum of three operands. There is a single ternary operator that is available in C++. The only available ternary operator in C++ is ? that is used as a substitute for an if-else statement.
Example: x>y ? x:y
Types of Operators in C++
- Arithmetic operators
- Logical operators
- Comparison operators
- Assignment operators
- Bitwise operators
- Comma operators
- Increment and Decrement operators
The operators that help the programmer in a mathematical calculation is known as arithmetic operators.
The operators that help the programmer to connect two or more expression is known as logical operators.
Comparison operators are those operators that are used to compare variables. It returns the value either true or false. They are also known as relational operators.
|=||Is equal to|
|!=||Is not equal to|
|>=||Greater than or equal to|
|<=||Less than or equal to|
Assignment operators are those operators that are used to assign values to the identifier. The assignment operator used in C++ is a “=” operator.
Example: x=5; (assigns the value 5 to x)
Bitwise operators are those operators that operate at a bit level and allows the programmer to manipulate individual bits. They are basically used for testing or shifting bits.
|<<||Binary Left Shift Operator|
|>>||Binary Right Shift Operator|
|&||Binary AND Operator|
|^||Binary XOR Operator|
||||Binary OR Operator|
|~||Binary One’s Complement Operator|
Comma operators in C++ are used to separate variable names or expression.
Increment and Decrement Operators
Increment and Decrement operators in C++ are used to increase and decrease the values of the operand respectively.