
Operands and operators
An operator is the part of an instruction that specifies the value to be operated on. An operator also carries out a specific operation on its operands. Examples of operators are +, -, *, /, and %. Operators can be categorized based on the type of operations carried out and the number of operands acted upon by the operator.
Based on the type of operations carried out by the operator, we can classify operators into:
- Relational operators
- Assignment operators
- Logical operators
- Arithmetic operators
- Bitwise operators
Operator type |
Examples |
Relational operators |
>, <, >=, <=, == |
Assignment operators |
+=, -=, *=, /=, = |
Logical operators |
&&, ||, ! |
Arithmetic operators |
+, -, *, / |
Bitwise operators |
and(bits), or(bits), xor(bits), inv(), shl(bits), shr(bits), ushr(bits) |
Based on the number of operands acted upon, we have two main types of operators in Kotlin:
- Unary operators
- Binary operators
Operator type |
Description |
Examples |
Unary operator |
Requires only one operand |
!, ++, - - |
Binary operator |
Requires two operands |
+, -, *, /, %, &&, || |