(1)
i=0;
a=(++i)+(++i);
then a==4
(2)
i=0;
a=(++i)+(++i)+(++i);
then a==7
(3)
i=0;
a=(++i)+(++i)+(++i)+(++i);
then a==11
i just test this with vc++ 6.0 & gcc 3.2 for win32
i wonder how to explain it.
about (++i)+(++i)
Moderator: Board moderators
-
- System administrator & Problemsetter
- Posts: 399
- Joined: Sat Jan 12, 2002 2:00 am
hmm
In turbo C++ the values the 4, 9 and 16 respectively which I find consistent with a certain rule.
Re: about (++i)+(++i)
ANSI C specifies that your examples have undefined behaviour.tiaral wrote:(1)
i=0;
a=(++i)+(++i);
then a==4
(2)
i=0;
a=(++i)+(++i)+(++i);
then a==7
(3)
i=0;
a=(++i)+(++i)+(++i)+(++i);
then a==11
i just test this with vc++ 6.0 & gcc 3.2 for win32
i wonder how to explain it.
The pre-increment operator has two meanings:
- - it returns a value
- as a side effect it increments the variable i
Look at this thread for another discussion about side effects and sequence points.
Ciao!!!
Claudio