[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Is the behavior unspecified or can it the expression be evaluated?

coolguyaroundyou

9/24/2008 8:08:00 PM

Here, analyse this snippet :

{
int a=1,b=0,c=0;


b=a+ ++a;...........Statement 1

a=1;

c=a+ a++;...........Statement 2

}


Both the statements,1 and 2, have side-effects. The standard says that
the order of evaluation of side-effects is unspecified. So,will the
values stored in b and c be implementation-defined?

I tried this in 2 compilers and the result was same, but the result of
the following in the same 2 compilers was different:

{
int a=1;


std::cout<<a<<++a;...........Statement 1

a=1;

std::cout<<a<<a++;...........Statement 2

}

Any reasons for such behavior in this case and also for the behavior
in the former code??