The task of the operator is to perform some operation on certain values(operands).
For example, 10 + 15,
where 10 and 15 are left and right operand and + is an operator.
- Assignment Operator
- Comparison operators
- Arithmetic operators
- Bitwise operators
- Logical operators
- String operators
- Conditional (ternary) operator
- Comma operator
- Unary operators
- Relational operators
The above operators can be grouped into the following type of operators.
- Unary operator and
- Binary operator
- Ternary operator(conditional operator).
Unary operator contains the single operand, either before or after the operator.
Binary operator contains the two operands, one before the operator and one after the operator.
operand1 operator operand2
1 + 2
Ternary operator (conditional operator)
Ternary operator is nothing but the short implementation of
if else loop. Ternary operator contains three operands. one operand is condition and two operands are values and it selected one of two values based on condition
condition ? value1 : value2
if a condition is true, the operator has value1 otherwise value2.