programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Devaka Cooray
• Ron McLeod
• Jeanne Boyarsky
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Piet Souris
• Carey Brown
• Tim Holloway
Bartenders:
• Martijn Verburg
• Frits Walraven
• Himai Minh

# doubt in precedence

Greenhorn
Posts: 14
• Number of slices to send:
Optional 'thank-you' note:
hi all,

1)x=x*2+3;

here right hand side of the expression is evaluated first i.e x*2+3

here precedence comes into play because we have two operands then *(multiplication) must be evaluated i.e x*2
followed by +

its explained in different way in K&B in OPERATORS TOPIC

X=X*(2+3)HOW IT POSSIBLE WHEN ITS NOT GIVEN IN ()

can any one clarify it,

Ranch Hand
Posts: 99
• Number of slices to send:
Optional 'thank-you' note:

X=X*(2+3)HOW IT POSSIBLE WHEN ITS NOT GIVEN IN ()

this can be achieved as
X *= 2+3
Both will generate the same output

Ranch Hand
Posts: 377
• Number of slices to send:
Optional 'thank-you' note:

please specify the page in the book.

Ranch Hand
Posts: 3389
• Number of slices to send:
Optional 'thank-you' note:
If you dont alter the preferences by putting the brackets explicitly, by default the * gets the precedence over the +.

But as Al Mamun said, if you wrote as *=, then it may work in the other way.

Greenhorn
Posts: 14
• Number of slices to send:
Optional 'thank-you' note:
thanks for response

YOU MEAN TO SAY X*=2+3; IS AN EXCEPTIONAL CASE FOR THE PRECEDENCE BUT WHAT ABOUT IF YOU HAVE X=Y*2+3 IT MUST BE X=(Y*2)+3;OR X=Y*(2+3);?

I think precedence rules are not properly discussed in K&B

Manfred Klug
Ranch Hand
Posts: 377
• Number of slices to send:
Optional 'thank-you' note: