Post and Pre increment operators

后端 未结 7 1034
面向向阳花
面向向阳花 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:11

    In Post increment operator value will of operand will increase after use. Example

    int k =1;
            int l = k++;
            System.out.println("...k..."+k+"...l.."+l);
    

    First k (value = 1) is assigned with l after that the k value will increase

    Similarly thing happens in the following line

    i = i++ + f1(i);
    

提交回复
热议问题