C#: Order of function evaluation (vs C)

后端 未结 8 600
旧时难觅i
旧时难觅i 2020-12-19 07:08

Take the following C code (K&R pg. 77) :

push(pop() - pop()); /* WRONG */

The book says that since - and /

8条回答
  •  庸人自扰
    2020-12-19 07:36

    From Fabulous Adventures In Coding: Precedence vs Associativity vs Order:

    Another way to look at it is that the rule in C# is not "do the parentheses first", but rather to parenthesize everything then recursively apply the rule "evaluate the left side, then evaluate the right side, then perform the operation".

提交回复
热议问题