The ++ and -- Operators
- There are two special operators in c/c++
- And they are where c++ gets part of its name.
- ++ is the increment operator
- a++;
- Equivalent to a = a + 1;
- -- is the detriment operator.
- a--;
- Equivalent to a = a - 1;
- These can be used in two ways
- Write a program to explore the difference.
- This is only a problem when these operators are used in complex statements
- i= i++ + ++i - ++i
Operator Assignment
- For most operators, you can also do a compound assignment.
- The form is var op= expression.
- a += 5
- This is the same as a = a + 5
- Or in general lhs op= rhs is the same as lhs = lhs op rhs;
Both of these forms of expression are acceptable (in simple computations) and are are frequently used.