Results 1 to 5 of 5
  1. #1
    rohitjava is offline Member
    Join Date
    Aug 2010
    Posts
    13
    Rep Power
    0

    Exclamation please help in java funda...

    Java Code:
    when x=5;
    System.out.println(x++ + ++x);
    output->12

    why it print 12
    anyone can tell me please....

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    what did you expect and why?

    EDIT: look in here too
    Last edited by eRaaaa; 10-18-2010 at 04:18 PM.

  3. #3
    rohitjava is offline Member
    Join Date
    Aug 2010
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by eRaaaa View Post
    what did you expect and why?

    EDIT: look in here too
    x++ gives->5
    ++x gives ->6
    so why
    System.out.println(x++ + ++x); gives ->12
    wts reason behind this..

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,819
    Rep Power
    19

    Default

    x++ evaluates to 5, which is then added to ++x which will evaluate to 7.

  5. #5
    gauravfzd's Avatar
    gauravfzd is offline Member
    Join Date
    Oct 2010
    Location
    India
    Posts
    72
    Rep Power
    0

    Default

    when x++ is encountered the value of x was 5, after x++ it becomes 6 then after encountering ++x the value of x becomes 6+1=7 which is then added to the previous value of x i.e. 5 to produce 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •