this is related to postfix and prefix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajit choudhary
    New Member
    • Apr 2012
    • 1

    this is related to postfix and prefix

    int a=5;
    int b=a-- + ++a + a++;
    cout<<a;

    it shows 15 but i am not getting understood that which has
    the highest priority..
    plz help...
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    None of them have the highest priority, this is undefined behaviour because you accessing a variable (a) more than once between sequence points were one (or more) of the accesses modifies its value.

    Once you have invoked undefined behaviour all bets are off the compiler is free to do as it wishes and so is the code it produces, you don't even have a guarantee that it will do the same thing twice in a row.

    Avoid constructs like this.

    Comment

    Working...