1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

increment decrement- controvresy Why?

Discussion in 'Meet and Greet' started by sreenivasan, Sep 7, 2011.

  1. sreenivasan

    sreenivasan New Member

    Joined:
    Sep 7, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    what is the value of cout<<++a + ++a + ++a if a=5;
    what is the value of b = ++a + ++a + ++a if a=5; cout<<b;
    See the difference . can any body tell why it is ? Pls help me.
     
  2. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    first one 21
    second one 18
    is it correct
    if it is then i will go with explanation
     
  3. sainishanth

    sainishanth New Member

    Joined:
    Feb 8, 2012
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    the value of b=24;
    a is preincremented 3 times.hence the value of a=8.
    then those get added 8+8+8=24;
    the value is same in both cases ;
     
  4. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    k i have mistaken
    what u have said is true for second case
    but for first one it will be 21
    please check it out
     
  5. dhilipmaths123

    dhilipmaths123 New Member

    Joined:
    Sep 14, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    we executed the statement(manually). it gave the same result i.e., 21. Maybe you could ask the complier to do it either c/c++
     

Share This Page