Manning's Countdown to 2014
. Use discount code crdotd14 all month for 50% off every deal.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
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
Java Operator Precedence and Associativity Table
What are operator precedence and the order of operand evaluation?
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
subject: operator precedence
Simple precedence question.
Logical operators (&& and ||)
boolean x = (a = true) || (b = true) && (c = true);
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013