parameter和argument的區別

來源:互聯網
上載者:User
parameter和argument的區別轉載自:http://smilejay.com/2011/11/parameter_argument/

在對一個函數寫一個注釋時,我在考慮到底該用parameter還是用argument來描述其參數呢。

根據網上一些資料,對parameter和argument的區別,做如下的簡單說明。

1. parameter是指函數定義中參數,而argument指的是函數調用時的實際參數。

2. 簡略描述為:parameter=形參(formal parameter), argument=實參(actual parameter)。

3. 在不很嚴格的情況下,現在二者可以混用,一般用argument,而parameter則比較少用。

While defining method, variables passed in the method are called parameters.
當定義方法時,傳遞到方法中的變數稱為參數.
While using those methods, values passed to those variables are called arguments.
當調用方法時,傳給變數的值稱為引數.(有時argument被翻譯為“引數“)

一個C++的例子來說明二者的區別:

[Copy to clipboard]View Code CPP

123456789101112
void func(int n, char * pc); //n and pc are parameterstemplate <class T> A {}; //T is a a parameter int main(){  char c;  char *p = &c;  func(5, p); //5 and p are arguments  A<long> a; //'long' is an argument  A<char> another_a; //'char' is an argument  return 0;}


如下敘述,來自wikipedia:
http://en.wikipedia.org/wiki/Parameter_%28computer_programming%29

Just as in standard mathematical usage, the argument is thus the actual value passed to a function, procedure, or routine (such as x in log x), whereas the parameter is a reference to that value inside the implementation of the function (log in this case).
See the Parameters and arguments section for more information.

Parameters and arguments
————————————————
These two terms are sometimes loosely used interchangeably; in particular, “argument” is sometimes used in place of “parameter”. Nevertheless, there is a difference. Properly, parameters appear in procedure definitions; arguments appear in procedure calls.

A parameter is an intrinsic property of the procedure, included in its definition. For example, in many languages, a minimal procedure to add two supplied integers together and calculate the sum total would need two parameters, one for each expected integer.
In general, a procedure may be defined with any number of parameters, or no parameters at all. If a procedure has parameters, the part of its definition that specifies the parameters is called its parameter list.

By contrast, the arguments are the values actually supplied to the procedure when it is called. Unlike the parameters, which form an unchanging part of the procedure’s definition, the arguments can, and often do, vary from call to call. Each time a procedure
is called, the part of the procedure call that specifies the arguments is called the argument list.

Although parameters are also commonly referred to as arguments, arguments are more properly thought of as the actual values or references assigned to the parameter variables when the subroutine is called at run-time. When discussing code that is calling
into a subroutine, any values or references passed into the subroutine are the arguments, and the place in the code where these values or references are given is the parameter list. When discussing the code inside the subroutine definition, the variables in
the subroutine’s parameter list are the parameters, while the values of the parameters at runtime are the arguments.

Many programmers use parameter and argument interchangeably, depending on context to distinguish the meaning. The term formal parameter refers to the variable as found in the function definition (parameter), while actual parameter refers to the actual value
passed (argument).

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.