V
Vijay Kumar R Zanvar
The following statement exchanges int a & b.
a = (a+b) - (b=a);
Is there any trade off here?
Thanks.
a = (a+b) - (b=a);
Is there any trade off here?
Thanks.
Vijay Kumar R Zanvar said:The following statement exchanges int a & b.
a = (a+b) - (b=a);
Is there any trade off here?
Vijay said:The following statement exchanges int a & b.
a = (a+b) - (b=a);
Is there any trade off here?
Did you not realise that the compiler is free to evaluate the operands
of -, +, and = in any order it finds convenient?
No, only a down side. It's not likely to work as stated. It'sThe following statement exchanges int a & b.
a = (a+b) - (b=a);
Is there any trade off here?
Thanks.
In said:No, only a down side. It's not likely to work as stated. It's
implementation dependent and possible even context dependent in a
given implementation.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.