Operator can be used to manipulate variable value. You can also perform arithmetic operations with number. Variable or number that's used with operator is called as operand.
There are some types of operator. Mostly used operators are arithmetic operator.
C++ have 5 arithmetic operators that you can use.
- Addition (+)
- Substarction (-)
- Multiplication (*)
- Division (/)
- Modulus (%)
5+2*3/4-2 = 4.5
Operators perform arithmetic operations by using hierarchy. It will be useful if you know PEMDAS rule. Multiplication and division will be performed first before Addition and substraction. You can use parentheses if you want to see different result.
Assignment Operator
Operator "=" is assignment operator in C++. You can use it to give value to a variable. You can store the result of arithmetic operations inside a variable by using this operator. You can print variable value to the output.
5+2*3/4-2 = 4.5
There are operators that come from combination of assignment operator and arithmetic operator. You can use it if you only use a variable.
- +=
- -=
- /=
- *=
- %=