When pass a variable to a function, why the function only gets a duplicate of the variable?

前端 未结 9 1290
野的像风
野的像风 2020-12-06 18:05

When pass a variable to a function, why the function only gets a copy/duplicate of the variable?

int n=1;

void foo(int i)
{
    i++;
}

As

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-06 18:32

    It is to make sure that the function doesn't change the original value.

提交回复
热议问题