Post and Pre increment operators

后端 未结 7 1032
面向向阳花
面向向阳花 2021-01-17 21:43

When i run the following example i get the output 0,2,1

class ZiggyTest2{

        static int f1(int i) {  
            System.out.print(i + \",\");  
               


        
7条回答
  •  被撕碎了的回忆
    2021-01-17 22:18

    To get In-depth you need to see Expression and its Evaluation Order

    Here's little explanation about equation i++ + f1(i) evaluation

    In Equation Compiler get "i" which is Equals to 1 and put it on stack as first operand then increments "i", so its value would be 2, and calculates second operand by calling function which would be 0 and at the time of operation (+) execution operands would be 1 and 0.

提交回复
热议问题