File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes C / C++ and the fly likes problems with expressions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Languages » C / C++
Bookmark "problems with expressions" Watch "problems with expressions" New topic
Author

problems with expressions

sovan chatt
Ranch Hand

Joined: Aug 09, 2010
Posts: 43

The output of the above code is -2 2 0 1
Why is this happening?I guess it should have been -2 3 1 1
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16


++i is true, so the rest will not be evaluated. ++j, ++k will not be executed.


[My Blog]
All roads lead to JavaRanch
rohan yadav
Ranch Hand

Joined: Oct 13, 2009
Posts: 156
Expressions are evaluated from left to right in c++,
As ++i is true, right hand side of || will not get evaluated.


Sage of The Monstrous Toad of Mount Myoboku
sovan chatt
Ranch Hand

Joined: Aug 09, 2010
Posts: 43
@rohan yadav,@Christophe Verré thanks...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36486
    
  16
rohan yadav wrote:Expressions are evaluated from left to right in c++ . . .
Is that a general rule, or does it only apply to expressions separated by && and ||?
rohan yadav
Ranch Hand

Joined: Oct 13, 2009
Posts: 156
I guess Left to right is general rule but i am not sure, I tried some generalized scenario's, i find left to right rule working properly,
But as i said i am not sure...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36486
    
  16
You would need to check the language specifications carefully; I know left-to-right is specified for Java, but I am not sure about C++.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problems with expressions
 
Similar Threads
loop question doubt
continue statement
Label???
Increment Test
project euler