|
In Basic, to inc/dec a variable you have to: VarName = VarName + 1
Lots of writing. However in C, you can use VarName++
You probably alread new this right? However, did you know that if you put the ++ in front of the variable name and use it in an expression, it means a whole new thought?
What about a loop starting with the value 1.
i = 1;
do {
printf("%i",i);
i++;
} while (i < 10);
How about:
i = 1;
do
printf("%i",i++);
while (i < 10);
And:
i = 1;
do
printf("%i",++i);
while (i < 10);
The first two listings do the exact thing. However, did you notice that the third listing printed 2 thorough 10 instead of 1 through 9? When the ++ is before the variable name, the compiler increments the variable first, then gets the value from it. It is the same with the other similar symbols.
¥
|