Pre/post increment/decrement and operator order confusion

前端 未结 4 1397
天命终不由人
天命终不由人 2021-01-15 07:45

I was going through some exercises but I am confused in this one:

public static int f (int x, int y) {
  int b=y--;
  while (b>0) {
    if (x%2!=0)  {
            


        
4条回答
  •  被撕碎了的回忆
    2021-01-15 08:44

    It's poor coding, as it can confuse new programmers.

    The function, assuming it is passing by value, like in the example above (as opposed to passing by reference) takes a copy of y, decrements it, and assigns it to b. It does not alter the argument passed to the function when it was called.

提交回复
热议问题