If you only want to increment a value by 1 , you can use the ++ operator. This goes either
directly before or after the variable.
So what's the difference between putting the ++ operator before or after the variable? The
main difference is the value that is returned by the operation. Both operations increase the
value of the points variable by 1 , but points++ will return the original value then in-
crease it by 1, whereas ++points will increase the value by 1, then return the new value:
points++; // will return 3, then increase points to 4
++points; // will increase points to 5, then return it
There is also a -- operator that works in the same way:
1e308; // 1 with 308 zeroes!
2e308; // too big!
Search WWH ::