Andrew Clark <> writes:
> Ben Pfaff <> wrote in
> news::
>
>> (Luai) writes:
>>
>>> in (for loops) there is no difference between incrementing the loop in
>>> these two ways:
>>>
>>> for (i=0; i < 10 ; ++i)
>>>
>>> and
>>>
>>> for (i=0; i < 10 ; i++)
>>
>> Why and how did you think they might be different?
>
> I recall an exam where I was marked off for writing one of these (I
> forget which one), and to correct it the instructor wrote the other one.
You'll have to be more specific. When ++i or i++ is a full
expression, they are equivalent. When one of them is a
subexpression of a larger expression, they may not be
equivalent. So if your instructor took off points in the former
case, he (or she) was simply wrong, but in the latter case he may
have been justified.
By the way, here is the definition of a "full expression", from
C99 6.8:
4 A full expression is an expression that is not part of another
expression or of a declarator. Each of the following is a
full expression: an initializer; the expression in an
expression statement; the controlling expression of a
selection statement (if or switch); the controlling
expression of a while or do statement; each of the
(optional) expressions of a for statement; the (optional)
expression in a return statement. The end of a full
expression is a sequence point.
--
Go not to Usenet for counsel, for they will say both no and yes.