[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

x = a++ + y++; what is x?

Posted on 2007-04-05
5
Medium Priority
?
846 Views
Last Modified: 2011-10-03
int x, a=6, y=7;
x = a++ + y++;

x will be 13,
but I think ++ has high precendence than + ,
so a++, y++ will be exercuted before +,
so I think x should be 15.

please let me know what is wrong in my think.

0
Comment
Question by:keepworking
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 14

Accepted Solution

by:
CPColin earned 1000 total points
ID: 18860370
The post-increment operator, ++, placed after a variable, returns the value first, then increments the variable. Thus the plus operator, +, gets the values 6 and 7.
0
 
LVL 8

Assisted Solution

by:mnrz
mnrz earned 400 total points
ID: 18860445
because ++ occured after the variable so it has not preceding over the +
it means after the action increment the value
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18860730
Yes, just look at it as:

x = a ++ + y ++ ;

becomes

x = ( a ++ ) + ( y ++ ) ;

So a ++ and y ++ are evaluated first (as the current values of a and y respectively) and then added to be assigned to x. The values of a and y are then incremented after the statement.
0
 

Author Comment

by:keepworking
ID: 18860783
mayankeagle:

it seems yu added the comment during I was closing it, so I missed yours, I am sorry. how to add points to you now?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18862234
You don't need to - its ok.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question