ouput of program is 5 8Code:void main(){ int a,b; a=b=1; a=a++ + ++b; b=b++ + ++a; printf("%d%d",a,b); }
how?
ouput of program is 5 8Code:void main(){ int a,b; a=b=1; a=a++ + ++b; b=b++ + ++a; printf("%d%d",a,b); }
how?
Yes, it's the same explanation as one of your previous "please explain" threads.
This is getting really old and tiresome...
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
when i calculate, i found answer 4 6
As before, the behaviour is undefined on these two lines:
Basically, whenever you see an a++ or ++a and you also see a somewhere else in the expression, it is likely that the behaviour is undefined. There are a few exceptions, perhaps most common is when the subexpressions are separated by && or || because these two operators introduce a sequence point.Code:a=a++ + ++b; b=b++ + ++a;
Undefined behaviour means that anything can happen. So, come up with whatever explanation you like, or compile to assembly and check the assembly output.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)