Function Arguments and Function Parameters (函数的实参和函数的形参)

Function Arguments and Function Parameters {函数的实参和函数的形参}

    1. Object-Oriented Programming Using C++
    1. Function Arguments and Function Parameters
  • References

1. Object-Oriented Programming Using C++

https://icarus.cs.weber.edu/~dab/cs1410/textbook/index.html
https://icarus.cs.weber.edu/~dab/cs1410/textbook/chapters.html

2. Function Arguments and Function Parameters

6.3. Function Arguments and Parameters
https://icarus.cs.weber.edu/~dab/cs1410/textbook/6.Functions/args.html

actual parameter = argument:实际参数,实参
formal parameter = parameter:形式参数,形参

While defining method, variables passed in the method are called parameters.

当定义方法时。

While using those methods, values passed to those variables are called arguments.

当调用方法时。

People, even experienced programmers, often use the terms argument and parameter interchangeably and rely on context to clarify the exact meaning (if an exact meaning is even needed). This practice generally doesn't cause any misunderstanding because whichever term they use describes the basic idea of passing data from a function call into a function for processing.

甚至是经验丰富的程序员经常交替使用术语 argument and parameter,并依靠上下文来阐明确切含义 (如果需要确切含义的话)。这种做法通常不会引起任何误解,因为无论他们使用哪个术语,都描述了将数据从函数调用传递到函数进行处理的基本思想。

Arguments are the values passed from a function call (i.e., they are the values appearing inside the call's parentheses) and sent to to a function. Parameters are local variables defined in the function (inside the parentheses in the function header) and used to hold the data passed into it.
Arguments 是从函数调用传递的值 (它们是出现在调用括号内的值) 并发送到函数。Parameters 是在函数中定义的局部变量 (在函数头的括号内),用于保存传递给它的数据。

The following example, based on pass-by-value, is the default passing technique and, therefore, the most familiar. However, C++ also supports two additional passing mechanisms: pass-by-pointer and pass-by-reference. The following sections explore and compare the details of the three passing techniques.


Figure 1. Argument vs. parameter.

The concepts of arguments and parameters are tightly linked. Like the sides of a coin, every argument has a corresponding parameter.

实参和形参的概念紧密相关。就像硬币的两面一样,每个实参都有对应的形参。

Sometimes, programmers use "formal" to denote the function side and "actual" to denote the call side: The program passes the actual parameters into the formal parameters. Except for pass-by-reference, passing data from an argument in the call to a parameter in the function behaves exactly like an assignment operation.

程序将实际参数传递给形式参数。除了按引用传递外,将数据从调用中的实参传递给函数中的形参的行为与赋值操作完全相同。

  • Argument Names and Parameter Names

When a function's arguments are variables, the argument names (in the function call) and the parameter names (in the function definition) may be the same, or they may be different.

When a program passes data into a function, it matches the arguments (in the call) to the parameters (in the function) based on position.

parameter 指的是函数定义中参数,而 argument 指的是函数调用时的实际参数。

So, each argument must correspond to exactly one parameter based on position. The program determines position by counting the comma-separated elements from left to right. All three argument-passing techniques share this positional matching.

每个实参必须根据位置与一个形参完全对应。程序通过从左到右计数逗号分隔的元素来确定位置。所有三种参数传递技术都共享此位置匹配。


Figure 2. Passing arguments to parameters.

Programs match function arguments with corresponding parameters based on their position within each list. Matching occurs in English reading order, from left to right, and there must be one argument for each parameter. The arguments must be the same data type as the parameters or be a type that the compiler can automatically promote to the parameter type.

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

相关推荐
钟山翼5 个月前
verilog 参数用法
verilog·参数·parameter·localparam
丁总学Java1 年前
项目实战:中央控制器实现(3)-优化Controller,处理普通的请求参数
java·method·parameter·getparameters·gettype·getname·parseint
丁总学Java1 年前
项目实战:中央控制器实现(4)-实现RequestBody注解的功能-获取请求体参数
java·注解·反射·requestbody·parameter
丁总学Java1 年前
微头条项目实战:新增RequestHeader注解
java·method·parameter·annotation
若石之上1 年前
详解Hugging Face Transformers的TrainingArguments
transformers·hugging face·training·argument·eval