How increment and decrement opertors works in c

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shivapadma
    New Member
    • Mar 2007
    • 40

    How increment and decrement opertors works in c

    i want clear explanation of increment and decrement operators in c.

    can any body help in solving the following expression
    a=10
    c=++a + ++a
    when i am executing this code ,the answer is c=24
    how it is possible?
  • hendrixx
    New Member
    • Jun 2007
    • 3

    #2
    well ++ hs higher precedence thn + and therefore ur expression becomes
    (++a) + (++a)
    and the result is 23 ;

    (11)+(12)

    Comment

    • ilikepython
      Recognized Expert Contributor
      • Feb 2007
      • 844

      #3
      Originally posted by hendrixx
      well ++ hs higher precedence thn + and therefore ur expression becomes
      (++a) + (++a)
      and the result is 23 ;

      (11)+(12)
      The result will be undefined. You shouldn't depend on that type of expressions because it could be anything.

      Comment

      • AdrianH
        Recognized Expert Top Contributor
        • Feb 2007
        • 1251

        #4
        Originally posted by ilikepython
        The result will be undefined. You shouldn't depend on that type of expressions because it could be anything.
        See here for more information.


        Adrian

        Comment

        Working...