参数和参数之间的区别参数、区别

2023-09-07 09:13:38 作者:你可爱的小祖宗

参数"和参数"之间是否有区别,或者它们只是同义词?

Is there a difference between a "parameter" and an "argument", or are they simply synonyms?

推荐答案

参数通常用于实际参数与形式参数的意义上.

形参是在函数声明/定义/原型中给出的,而实参是调用函数时传递的——a的实例形式参数,如果你愿意的话.

The formal parameter is what is given in the function declaration/definition/prototype, while the actual argument is what is passed when calling the function — an instance of a formal parameter, if you will.

话虽如此,它们通常可以互换使用,它们的确切用途取决于不同的编程语言及其社区.比如我也听说过实参等

That being said, they are often used interchangeably, their exact use depending on different programming languages and their communities. For example, I have also heard actual parameter etc.

所以这里 xy 将是形式参数:

So here, x and y would be formal parameters:

int foo(int x, int y) {
    ...
}

而这里,在函数调用中,5 和 z 是实际参数:

Whereas here, in the function call, 5 and z are the actual arguments:

foo(5, z);