A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
OCA Java SE 8 Programmer I Study Guide 1Z0-808
this week in the
Programmer Certification (SCJP/OCPJP)
Joined: Aug 29, 2006
Aug 29, 2006 04:06:00
I am new to
preparation group. so first hi to all..
iam not absolutely clear about operator precedence .
static boolean a,b,c,d;
public static void main(
d = (a=true) || (b=true) && (c=true);
doubt:&& has higher precedence than || then why || is evaluated first.
suggest me a clear guide/tutorial for operator precedence and associativity.
Joined: Jun 06, 2005
Aug 29, 2006 04:31:00
So the answer to your question goes as below
Evaluate: ((a=true) || ((b=true) && (c=true)));
Evaluate: ((true) || ((b=true) && (c=true))); // a=true is executed
As it knows true || something is always true (short circuited), the control breaks at this step without executing the further statements for b and c
So the result is a=true b=false and c=false
Joined: Feb 02, 2006
Aug 29, 2006 07:07:00
Operator Precedence and Associativity Table
What are operator precedence and the order of operand evaluation?
I agree. Here's the link:
subject: operator precedence
Logical operators (&& and ||)
boolean x = (a = true) || (b = true) && (c = true);
Simple precedence question.
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015