February 2009
Beginner
128 pages
2h 45m
English
These are special operators used to make code more concise for some very common operations like incrementing a value.
For example, to increment value by 1 you would write:
value = value +1;
but using a compound operator, this becomes:
value++;
These increment or decrement a value by 1. Be careful, though. If you write i++ this increments i by 1 and evaluates to the equivalent of i+1; ++i evaluates to the value of i then increments i. The same applies to ––.
These make it shorter to write certain expressions. The following two expressions are equivalent:
a = a + 5; a += 5;
Read now
Unlock full access