wat does +++ do???

Discussion in 'C' started by IndiraP, Nov 17, 2012.

  1. IndiraP

    IndiraP New Member

    Joined:
    Nov 10, 2012
    Messages:
    41
    Likes Received:
    2
    Trophy Points:
    0
    Code:
    main() 
    { 
        int a=10,b=20,c; 
        c = a+++b; 
        printf("%d",c); 
    }
    
    output is 30..

    how does this work???
     
    Last edited by a moderator: Nov 18, 2012
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,345
    Likes Received:
    382
    Trophy Points:
    83
    ++ increments a and next + is an addition
     
  3. IndiraP

    IndiraP New Member

    Joined:
    Nov 10, 2012
    Messages:
    41
    Likes Received:
    2
    Trophy Points:
    0
    yes sir...forgot dat was a post increment..
    so a+b n then a is incremented..
    thank u sir..:)
     
  4. debugEnthu

    debugEnthu New Member

    Joined:
    Jul 5, 2012
    Messages:
    11
    Likes Received:
    3
    Trophy Points:
    0
    Just to add...
    Maximum munch rule is follwed here.
    ie: It uses
    (a++ ) + b
    instead of
    a + (++b)
     
  5. IndiraP

    IndiraP New Member

    Joined:
    Nov 10, 2012
    Messages:
    41
    Likes Received:
    2
    Trophy Points:
    0
    thank u for the info..:)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice