--- In [email protected], David <[EMAIL PROTECTED]> wrote:
>
> dokhtar_e_sharghi1987z a �crit :
> > hi all,
> >
> > #include<iostream.h>
> > main()
> > { int x ;
> > x=9 ; x=++x + ++x + x; cout<<x ;
> > x=9 ; cout<<++x + ++x + x ;
> > x=9 ; cout<<x + x++ +x ;
> > x=9 ; x=x + x++ +x; cout<<x ;
> > return 0;
> > }
> >
> > why the out put is: 33332728
>
> by luck
>
> btw, iostream.h is deprecated, main() must be at least
> int main(), and return 0; is implicit in C++ at the main
> of the main
> probably someone willl advise you to change your compiler.
Good short reply.
Here's the longer version: as you constantly change x several times
between sequence points (roughly spoken, between two semicolons), you
invoke undefined behaviour. And the term "undefined behaviour" means
exactly what it says: you're doing something which is silly to do.
You don't know what undefined behaviour is? Then go to Wikipedia,
enter the search word "Nasal Demon", and look under the second link
("undefined behaviour").
Regards,
Nico