In article <11**********************@e3g2000cwe.googlegroups. com>,
howa <ho******@gmail.comwrote:
> int n , i = 10, j =20, y=100, x = 3;
n = ( i < j ) || (y +=i) ;
cout<<y;
// why y = 100, but not 110, as y +=i , y = y + i
This is so-called short-circuting of expressions.
When expressions are seperated by || it will take each in turn,
if the value of the current is false, it continues to the next;
if the value of the current is true, the full expression is deemed
successful and no need to continue to be more successful
therefore subsequent parts are not evaluated to be more successful.
In your specific example i is < j, therefore, the y+=i expression
is not evaluated.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in beta!
Comeau C/C++ ONLINE ==
http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?