Operator associativity in C specifically prefix and postfix increment and decrement

后端 未结 3 1559
梦谈多话
梦谈多话 2021-01-06 05:24

In C operation associativity is as such for increment, decrement and assignment.

  2. postfix ++ and -- 
  3. prefix ++ and -- 
  16. Direct assignment = 
<         


        
3条回答
  •  生来不讨喜
    2021-01-06 05:58

    The postfix operator a++ will increment a and then return the original value i.e. similar to this:

    { temp=a; a=a+1; return temp; }
    

    and the prefix ++a will return the new value i.e.

    { a=a+1; return a; }
    

    This is irrelevant to the operator precedence.

    (And associativity governs whether a-b-c equals to (a-b)-c or a-(b-c).)

提交回复
热议问题