Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Conditional Operator doubt?

 
Joe Harry
Ranch Hand
Posts: 10106
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Consider the following code and please help me to interpret the same.

boolean b1 = false?false:true?false:true?false:true;

How to group them to find the solution??
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ternary operator is right-associative so



is the same as

.
[ December 06, 2006: Message edited by: Keith Lynn ]
 
Joe Harry
Ranch Hand
Posts: 10106
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will be the result of that?? How condiotional operator works in the above case??
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In any ternary operator, the form is

 
Micheal John
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and you have to solve it from right to left
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Micheal John:
and you have to solve it from right to left



Why? Once it is correctly parenthesized it can be evaluated more efficiently from left to right.
 
Harish Paravasthu
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haii,

if its formatted in braces,then go according to it..else go for right to left as said above.

answer is false...

harish
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic