Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
postfix, prefix and arithmetic operator precedence query
Vijay Kumar Raman
Greenhorn
Posts: 15
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
class TestPrecedence { public static void main(String args[]){ int x = 1; System.out.println( x++ + x++ * --x ); } }
output : 8
x++ + x++ * --x
2 + x++ * --x
2 + 3 * --x
2 + 3 * 2
2 + 6
result: 8
Is this correct ?
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
posted 6 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
No.
x++
is a post-increment operation. It returns the old value of
x
, not the new one:
x++ + x++ * --x // x == 1 1 + x++ * --x // x == 2 1 + 2 * --x // x == 3 1 + 2 * 2 // x == 2 1 + 4 // x == 2 5 // x == 2
Vijay Kumar Raman
Greenhorn
Posts: 15
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Stephan,
Thanks for the answer.
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
understanding operator precedence
SCJP 5 Guide by K&B: Q5. Page 391 / 402
Operator precedence
post increment operator
explain this
More...