Lim is decreasing, you probably made a mistake elsewhere. However, --lim
is not quite equal to lim = lim - 1
.
There are two operators to perform increment/decrement of a variable: pre-increment(or decrement), and post-increment(or decrement).
++x
(pre-inc) and x++
(post-inc) both modify the value of x by +1. So what's the difference?
When you use x++
in an expression, the expression will consider x to have it's current value and after evaluating everything accordingly, increment that value by one. So...
int x = 5;
printf("%d", x++);
... will print out 5. HOWEVER, after the printf() line, the value of x will be 6.
Pre-increment works the other way round: the value of x it's first incremented, and then considered to evaluate the expression surrounding it. So...
int x = 5;
printf("%d", ++x);
... will print out 6 and, of course, the value of x will be 6 after that.
Of course, the same applies to the decrement operators.
Now, the assignment operation (x = x + 1
) evaluates to the value assigned, after the assignment happened, so its behavior is actually similar to ++x
, not x++
.