What if the operator [++] or [--] is used twice or more within a while-loop?

Hello fellows,

I am curious to know the real effect on my variable Lower in this loop:

while(Lower > 0
&& ITGW[--Lower][0] < dMaxIT
&& ITGW[--Lower][0] > ITGW[m][0]);

I am expecting that the variable Lower be decremented at the same time.

Will it be so?

Thanks.
'Lower' is decremented in that order the expressions are evaluated.
Simply put, using a variable that's being incremented or decremented more than once inside the same expression has undefined behavior (technically, the rule is more complicated, but this is a good enough approximation). Meaning that there's no way of knowing beforehand what the value of Lower is after or during the expression.
For example:
(a++)+(++a)
(a++)+(a--)
(a++)+a
Last edited on
Topic archived. No new replies allowed.