On Wed, May 27, 2009 at 4:19 PM, Arvind Balodia
<[email protected]> wrote:
> Ok well i checked for your output but unlike you
> i found the same answer in both the cases and that was that
> it must be i.e. 12;
> In the assigning statement of v
> you are telling the compiler like this
> (m++)+(++m)
> it means first take m and after the execution increase its value by 1 and
> add m again but before the execution increase its value by 1
> so before the execution of the above statement the value of m
> is set to 6(by an increment of 1)
> and yeah the result will be generated as m+m
> i.e.6+6 =12
> after the execution of statement the m
> will be set to 7
> So the answer is 12.
> please have a look once again on your program.

Please don't encourage the use of such constructs. As Paul already
pointed out, you are not allowed to modify one variable more than once
between two sequence points.
What you are experiencing is undefined behavior. A compiler could
generate code that overwrites the hard drive with garbage data for
such a code, and still be standards-compliant.
Repeat after me: I will not change a variable more than once between
two sequence points!


-- 
Tamas Marki

Reply via email to