Solved

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

Posted on 2007-04-05
5
842 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 250 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 100 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android development question 2 108
difference between sorce folder and folder in eclipise 3 64
ejb entity bean example 2 57
learn programming 8 94
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

734 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