参数和形参有什么区别?

发布于 2024-07-05 18:31:19 字数 409 浏览 6 评论 0原文

当口头谈论方法时,我不确定是否使用“参数”或“参数”或其他词。 不管怎样,其他人都知道我的意思,但什么是正确的,这些术语的历史是什么?

我是一名 C# 程序员,但我也想知道人们是否在不同的语言中使用不同的术语。

根据记录,我是自学成才,没有计算机科学背景。 (请不要告诉我阅读代码完整< /a> 因为我问这个是为了那些还没有 Steve McConnell 一本精彩的书。)

When verbally talking about methods, I'm never sure whether to use the word argument or parameter or something else. Either way the other people know what I mean, but what's correct, and what's the history of the terms?

I'm a C# programmer, but I also wonder whether people use different terms in different languages.

For the record I'm self-taught without a background in Computer Science. (Please don't tell me to read Code Complete because I'm asking this for the benefit of other people who don't already have a copy of Steve McConnell's marvelous book.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

空气里的味道 2024-07-12 18:31:20

参数是函数定义中的变量
参数是参数的

<?php

    /* define function */
    function myFunction($parameter1, $parameter2)
    {
        echo "This is value of paramater 1: {$parameter1} <br />";
        echo "This is value of paramater 2: {$parameter2} <br />";
    }

    /* call function with arguments*/
    myFunction(1, 2);

?>

Parameter is a variable in a function definition
Argument is a value of parameter

<?php

    /* define function */
    function myFunction($parameter1, $parameter2)
    {
        echo "This is value of paramater 1: {$parameter1} <br />";
        echo "This is value of paramater 2: {$parameter2} <br />";
    }

    /* call function with arguments*/
    myFunction(1, 2);

?>
痴情换悲伤 2024-07-12 18:31:20

它在参数(计算机编程)-维基百科中得到了完美的解释

。是类型,参数是实例。

在函数定义中,f(x) = x*x 变量x 是一个参数; 在函数调用 f(2) 中,值 ``2 是函数的参数。

以及 参数 - 维基百科

计算机编程的两个概念参数是常用的,被称为参数和参数——或者更正式地称为形式参数实际参数

例如,在函数的定义中,如

y = f(x) = x + 2,

x形式参数(定义函数的参数)。

当函数针对给定值进行计算时,如

f(3):或 y = f(3) = 3 + 2 = 5,

实际参数参数)用于通过定义的函数进行评估; 它是一个给定值(实际值),用于替换定义函数的形式参数。 (在随意使用时,术语参数参数可能会无意中互换,从而导致错误使用。)

It's explained perfectly in Parameter (computer programming) - Wikipedia

Loosely, a parameter is a type, and an argument is an instance.

In the function definition f(x) = x*x the variable x is a parameter; in the function call f(2) the value ``2 is the argument of the function.

And Parameter - Wikipedia

In computer programming, two notions of parameter are commonly used, and are referred to as parameters and arguments—or more formally as a formal parameter and an actual parameter.

For example, in the definition of a function such as

y = f(x) = x + 2,

x is the formal parameter (the parameter) of the defined function.

When the function is evaluated for a given value, as in

f(3): or, y = f(3) = 3 + 2 = 5,

is the actual parameter (the argument) for evaluation by the defined function; it is a given value (actual value) that is substituted for the formal parameter of the defined function. (In casual usage the terms parameter and argument might inadvertently be interchanged, and thereby used incorrectly.)

末蓝 2024-07-12 18:31:20

我想了想,发现我之前的回答是错误的。 这里有一个更好的定义

{想象一盒鸡蛋:一包香肠链接:还有一个女仆}这些代表了准备过程所需的函数的元素,称为:(使用任何名称:可以说烹饪是我的函数的名称)。

女仆是一种方法。

(你必须__call_或请求这个方法来制作早餐)(制作早餐的行为是一个函数,称为烹饪)_

鸡蛋和香肠是参数:(

因为您想吃的鸡蛋和/或香肠的数量是 __variable_ 。)_

您的决定是一个参数:

它代表您正在烹饪的所选鸡蛋和/或香肠数量的 __Value_ 。_

{助记}

_“当你打电话给女仆并要求她做早餐时,她会与你__争论_你应该吃多少鸡蛋和香肠。她担心你的胆固醇”__

(那么,争论就是价值观对于您已声明并决定传递给您的 Function 的参数组合)

I thought it through and realized my previous answer was wrong. Here's a much better definition

{Imagine a carton of eggs: A pack of sausage links: And a maid } These represent elements of a Function needed for preparation called : (use any name: Lets say Cooking is the name of my function).

A Maid is a method .

( You must __call_ or ask this method to make breakfast)(The act of making breakfast is a Function called Cooking)_

Eggs and sausages are Parameters :

(because the number of eggs and the number of sausages you want to eat is __variable_ .)_

Your decision is an Argument :

It represents the __Value_ of the chosen number of eggs and/or sausages you are Cooking ._

{Mnemonic}

_" When you call the maid and ask her to make breakfast, she __argues_ with you about how many eggs and sausages you should eating. She's concerned about your cholesterol" __

( Arguments , then, are the values for the combination of Parameters you have declared and decided to pass to your Function )

混浊又暗下来 2024-07-12 18:31:20

永远记住:
在接收参数时传递参数。

Always Remember that:
Arguments are passed while parameters are received.

日暮斜阳 2024-07-12 18:31:20

在编辑过程中,我经常对人们忘记的事情感到困惑:结构语言是基于自然语言的。

在英语中,

“参数”是一个占位符。 他们用口语设置响应格式。 根据定义,它是呼叫的一方,限制响应。

“论点”是正在考虑的立场。 你争论你的观点:你考虑一个论点。

主要区别

论证的主题角色是主体。 参数的主题角色是接收者。

交互

将参数视为男性部分,将参数视为女性部分。 参数进入参数。

用法

参数通常用在定义中。 参数通常在调用中使用。

问题

完成句子,使其不那么不和谐。

(A) 谈到定义:

  1. 将使用什么论证[]?
  2. 这个参数[]会是什么?

(B) 说到调用:

  1. 您将使用什么参数,[]?
  2. []这个参数会是什么?

答案

(A)

  1. 关于/在/反对/使用此参数
  2. 参数...采取

(B)

  1. 以及一些示例参数
  2. 参数...用于/在/反对/与

重叠

正如你可以想象的那样,回答后:在口语中,这些词有时会产生相同的反应!

因此,通常来说:

  • 通常,如果有人想要参数信息,他们想了解有关类型、变量名称等的更多信息。如果您只提供示例参数,他们可能会感到困惑。

    • 通常,如果有人想要参数信息,他们想知道您传递给函数或其参数的值。

In editing, I'm often put off at how people forget: structure languages are based on natural languages.

In English

A "parameter" is a placeholder. They set the response format, in spoken language. By definition, it's party to the call, limiting the response.

An "argument" is a position that is being considered. You argue your opinion: you consider an argument.

Main difference

The thematic role of an argument is agent. The thematic role of parameter is recipient.

Interactions

Think of the argument as the male part, making the parameter the female part. The argument goes into the parameter.

Usage

A parameter is usually used in definitions. An argument is usually used in invocations.

Questions

Finish the sentence to make it less dissonant.

(A) Speaking of a definition:

  1. What argument will be used []?
  2. What [] will this parameter []?

(B) Speaking of an invocation:

  1. What parameter will you use, []?
  2. What [] will be [] this parameter?

Answers

(A)

  1. on/in/against/with this parameter
  2. argument(s) ... take

(B)

  1. and what are some example arguments
  2. argument(s) ... used on/in/against/with

Overlaps

As you can imagine, after answering: in spoken language, these words will sometimes produce identical responses!

So, as a rule:

  • Usually if someone wants parameter information, they want to know more about the type, the variable name, etc. They may become confused if you only give example arguments.

    • Usually if someone wants argument information, they want to know what value you passed to a function or its parameter(s).
橙味迷妹 2024-07-12 18:31:20

或者,在方法的可选参数的情况下,这样记住可能更简单:

public void Method(string parameter = "argument") 
{

}

parameter 是参数,它的值,"argument" 是参数:)

Or maybe it's even simpler to remember like this, in case of optional arguments for a method:

public void Method(string parameter = "argument") 
{

}

parameter is the parameter, its value, "argument" is the argument :)

差↓一点笑了 2024-07-12 18:31:20

这个例子可能会有所帮助。

int main () {
   int x = 5; 
   int y = 4;

   sum(x, y); // **x and y are arguments**
}

int sum(int one, int two) { // **one and two are parameters**
   return one + two;
}

This example might help.

int main () {
   int x = 5; 
   int y = 4;

   sum(x, y); // **x and y are arguments**
}

int sum(int one, int two) { // **one and two are parameters**
   return one + two;
}
情魔剑神 2024-07-12 18:31:20

函数/方法的参数向您描述它用于计算其结果的值。

函数的参数是在函数/方法的特定调用期间分配给这些参数的值。

The parameters of a function/method describe to you the values that it uses to calculate its result.

The arguments of a function are the values assigned to these parameters during a particular call of the function/method.

梅倚清风 2024-07-12 18:31:20

这些术语在某种程度上可以互换。 其他答案中描述的区别可以使用术语“形式参数”(表示函数体内使用的名称)和“参数”(表示调用站点提供的值)来更正确地表达( 正式论证论证也很常见)。

另请注意,在数学中,术语参数更为常见,参数通常意味着完全不同的东西(尽管参数方程中的参数本质上是两个或多个函数的参数)。

The terms are somewhat interchangeable. The distinction described in other answers is more properly expressed with the terms formal parameter for the name used inside the body of the function and parameter for the value supplied at the call site (formal argument and argument are also common).

Also note that, in mathematics, the term argument is far more common and parameter usually means something quite different (though the parameter in a parametric equation is essentially the argument to two or more functions).

情深如许 2024-07-12 18:31:20

参数和参数

与参数和实参有关的所有不同术语
可能会令人困惑。 但是,如果您牢记一些简单的要点,
您将能够轻松处理这些条款。

  1. 函数的形参在函数声明中列出,并在函数定义的主体中使用。 A
    形式参数(任何类型)是一种空白或占位符,
    调用函数时会填充一些内容。
  2. 参数是用来填充形式参数的东西。
    当您写下函数调用时,参数列在
    函数名后面的括号。 当函数调用是
    执行时,参数将被插入形式参数。
  3. 术语“按值调用”和“按引用调用”指的是该机制
    在插入过程中使用。 在按值调用方法中
    仅使用参数的值。 在这个按值调用
    机制,形式参数是一个局部变量,即
    初始化为相应参数的值。 在里面
    引用调用机制参数是一个变量并且
    使用整个变量。 在引用调用机制中
    参数变量替换形式参数,以便
    对形式参数所做的任何更改实际上都是为了
    参数变量。

资料来源:Absolute C++,Walter Savitch

在此处输入图像描述

Parameters and Arguments

All the different terms that have to do with parameters and arguments
can be confusing. However, if you keep a few simple points in mind,
you will be able to easily handle these terms.

  1. The formal parameters for a function are listed in the function declaration and are used in the body of the function definition. A
    formal parameter (of any sort) is a kind of blank or placeholder that
    is filled in with something when the function is called.
  2. An argument is something that is used to fill in a formal parameter.
    When you write down a function call, the arguments are listed in
    parentheses after the function name. When the function call is
    executed, the arguments are plugged in for the formal parameters.
  3. The terms call-by-value and call-by-reference refer to the mechanism
    that is used in the plugging-in process. In the call-by-value method
    only the value of the argument is used. In this call-by-value
    mechanism, the formal parameter is a local variable that is
    initialized to the value of the corresponding argument. In the
    call-by-reference mechanism the argument is a variable and the
    entire variable is used. In the call- by-reference mechanism the
    argument variable is substituted for the formal parameter so that
    any change that is made to the formal parameter is actually made to
    the argument variable.

Source: Absolute C++, Walter Savitch

That is,

enter image description here

泅渡 2024-07-12 18:31:20

参数是参数的实例化。

An argument is an instantiation of a parameter.

束缚m 2024-07-12 18:31:20

是的! 参数和参数有不同的含义,可以简单地解释如下:

函数参数是函数定义中列出的名称。

函数参数是传递给函数(并由函数接收)的实际值。

Yes! Parameters and Arguments have different meanings, which can be easily explained as follows:

Function Parameters are the names listed in the function definition.

Function Arguments are the real values passed to (and received by) the function.

是伱的 2024-07-12 18:31:20

参数p赋予p参数的实际值。

Arguments are actual values passed to parameters.

漆黑的白昼 2024-07-12 18:31:20

我对所有这些答案仍然不满意。 他们都开始谈论“函数声明”,而我的猴子大脑已经开始思考独角兽了。 这根本不能帮助我记住,这只是定义。

我想要一些可以立即并永远留在我脑海中的东西。

我很快理解的这里唯一的答案是:

参数参数是传入的实际值”。


参数更容易定义,只要您知道它们是什么,那么您就知道参数是另一个。

我能想到的另一种方式是:

  • 参数外部的变量
  • 参数内部的变量该函数

简化为:

参数在外面,参数在里面

如果有人不同意我的观点,你可以把你的参数放在外面;)

I'm still not happy with all these answers. They all start talking about "function declarations" and my monkey brain has already wandered off and started thinking about unicorns. That doesn't help me remember at all, it's just the definition.

I want something that I can immediately and forever hold in my head.

The only answer here that I quickly understand is:

"Arguments are actual values that are passed in".

Arguments are easier to define and as long as you know what they are then you know parameters are the other.

The other way I can think of it is:

  • Arguments are the variables outside the function
  • Parameters are the variables inside the function

Simplified down to:

Arguments outside, parameters inside

If any one wants to disagree with me, you can leave your arguments outside ;)

旧时光的容颜 2024-07-12 18:31:20

无需代码的简单解释

“参数”是一个非常普遍、广泛的事物,但“参数:是一个非常具体、具体的事物。这可以通过日常示例来最好地说明:

示例 1:自动售货机 - 钱是参数,$2.00 是参数

大多数机器接受输入并返回输出。例如,自动售货机将金钱作为输入,并返回碳酸饮料作为输出。在这种特殊情况下,它接受参数:金钱

。参数?如果我将 $2.00 放入机器中,则参数为: $2.00 - 这是使用的非常具体的输入。

示例 2:汽车 - 汽油是参数

让我们考虑一辆汽车:它们接受汽油(无铅汽油)作为输入。可以说,这些机器接受类型为“汽油”的参数。参数将是我输入到我的汽车中的精确且具体的输入。参数将是:40 升无铅汽油/汽油

示例 3 - 参数的详细说明

参数是输入的特定且具体的示例。 假设我的机器将一个人作为输入并将其变成一个不是骗子的人。

那么什么是论证呢? 参数将是实际放入机器中的特定人。 例如,如果将 Colin Powell 放入机器中,则参数将是 Colin Powell。

因此,参数将是作为抽象概念的人,但参数始终是具有特定名称<的特定人< /strong> 谁被放入机器中。 论证是具体的、具体的。

这就是区别。 简单的。

使困惑?

发表评论,我会修正解释。

Simple Explanations without code

A "parameter" is a very general, broad thing, but an "argument: is a very specific, concrete thing. This is best illustrated via everyday examples:

Example 1: Vending Machines - Money is the parameter, $2.00 is the argument

Most machines take an input and return an output. For example a vending machine takes as an input: money, and returns: fizzy drinks as the output. In that particular case, it accepts as a parameter: money.

What then is the argument? Well if I put $2.00 into the machine, then the argument is: $2.00 - it is the very specific input used.

Example 2: Cars - Petrol is the parameter

Let's consider a car: they accept petrol (unleaded gasoline) as an input. It can be said that these machines accept parameters of type: petrol. The argument would be the exact and concrete input I put into my car. e.g. In my case, the argument would be: 40 litres of unleaded petrol/gasoline.

Example 3 - Elaboration on Arguments

An argument is a particular and specific example of an input. Suppose my machine takes a person as an input and turns them into someone who isn't a liar.

What then is an argument? The argument will be the particular person who is actually put into the machine. e.g. if Colin Powell is put into the machine then the argument would be Colin Powell.

So the parameter would be a person as an abstract concept, but the argument would always be a particular person with a particular name who is put into the machine. The argument is specific and concrete.

That's the difference. Simple.

Confused?

Post a comment and I'll fix up the explanation.

少女净妖师 2024-07-12 18:31:20

它们在 C 中的用法没有太大区别,这两个术语都使用
在实践中。
大多数参数经常与函数一起使用。 函数调用语句传递的值称为参数,参数是在函数定义中复制该值的变量(称为形式参数)。

int main ()
{
   /* local variable definition */
   int a = 100;
   int b = 200;
   int ret;

   /* calling a function to get max value */
   ret = max(a, b);

   printf( "Max value is : %d\n", ret );

   return 0;
}

/* function returning the max between two numbers */
int max(int num1, int num2) 
{
   /* local variable declaration */
   int result;

   if (num1 > num2)
      result = num1;
   else
      result = num2;

   return result; 
}

在上面的代码中,num1num2是形式参数,ab是实际参数。

They both dont have much difference in usage in C, both the terms are used
in practice.
Mostly arguments are often used with functions. The value passed with the function calling statement is called the argument, And the parameter would be the variable which copies the value in the function definition (called as formal parameter).

int main ()
{
   /* local variable definition */
   int a = 100;
   int b = 200;
   int ret;

   /* calling a function to get max value */
   ret = max(a, b);

   printf( "Max value is : %d\n", ret );

   return 0;
}

/* function returning the max between two numbers */
int max(int num1, int num2) 
{
   /* local variable declaration */
   int result;

   if (num1 > num2)
      result = num1;
   else
      result = num2;

   return result; 
}

In the above code num1 and num2 are formal parameters and a and b are actual arguments.

千纸鹤带着心事 2024-07-12 18:31:20

Oracle 的 Java 教程这样定义了这种区别:
“参数是指方法声明中的变量列表。参数是调用方法时传入的实际值。调用方法时,使用的参数必须在类型和顺序上与声明的参数匹配。”

参数和参数的更详细讨论:
https://docs.oracle.com/javase/tutorial/java/javaOO /arguments.html

Oracle's Java tutorials define this distinction thusly:
"Parameters refers to the list of variables in a method declaration. Arguments are the actual values that are passed in when the method is invoked. When you invoke a method, the arguments used must match the declaration's parameters in type and order."

A more detailed discussion of parameters and arguments:
https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html

万水千山粽是情ミ 2024-07-12 18:31:20

或者更简单...

参数输入!

参数输出!

Or even simpler...

Arguments in !

Parameters out !

瞳孔里扚悲伤 2024-07-12 18:31:20

从逻辑上讲,我们实际上在谈论同一件事。
但我认为一个简单的比喻将有助于解决这个困境。

如果这些隐喻可以称为各种连接点,我们可以将它们等同于墙上的插头点。
在这种情况下,我们可以考虑如下的参数和参数;

参数是插头的插座,可以采用各种不同的形状。 但只有某些类型的插头适合它们。
参数将是插入插头点/插座以激活某些设备的实际插头。

Logically speaking,we're actually talking about the same thing.
But I think a simple metaphor would be helpful to solve this dilemma.

If the metaphors can be called various connection point we can equate them to plug points on a wall.
In this case we can consider parameters and arguments as follows;

Parameters are the sockets of the plug-point which may take various different shapes. But only certain types of plugs fit them.
Arguments will be the actual plugs that would be plugged into the plug points/sockets to activate certain equipments.

哽咽笑 2024-07-12 18:31:20

当我们在Java中创建方法(函数)时,方法是这样的。

方法的数据类型名称(data-type variable-name)

括号里的这些是参数,当我们调用方法(函数)时,我们传递这个参数的值,这些参数称为参数。

When we create the method (function) in Java, the method like this..

data-type name of the method (data-type variable-name)

In the parenthesis, these are the parameters, and when we call the method (function) we pass the value of this parameter, which are called the arguments.

一指流沙 2024-07-12 18:31:20

根据 Joseph 的 Alabahari 著作“C# in a Nutshell”(C# 7.0,第 49 页):

static void Foo (int x)
{
    x = x + 1; // When you're talking in context of this method x is parameter
    Console.WriteLine (x);
}
static void Main()
{
    Foo (8); // an argument of 8. 
             // When you're talking from the outer scope point of view
}

在某些人类语言(据我所知,意大利语、俄语)中,这些术语广泛使用同义词。

  • 参数 = 形式参数
  • 参数 = 实际参数

在我的大学里,教授使用这两种名称。

According to Joseph's Alabahari book "C# in a Nutshell" (C# 7.0, p. 49) :

static void Foo (int x)
{
    x = x + 1; // When you're talking in context of this method x is parameter
    Console.WriteLine (x);
}
static void Main()
{
    Foo (8); // an argument of 8. 
             // When you're talking from the outer scope point of view
}

In some human languages (afaik Italian, Russian) synonyms are widely used for these terms.

  • parameter = formal parameter
  • argument = actual parameter

In my university professors use both kind of names.

小嗲 2024-07-12 18:31:19

参数是方法定义中的变量。 调用方法时,参数是传递给方法参数的数据。

public void MyMethod(string myParam) { }

...

string myArg1 = "this is my argument";
myClass.MyMethod(myArg1);

A parameter is a variable in a method definition. When a method is called, the arguments are the data you pass into the method's parameters.

public void MyMethod(string myParam) { }

...

string myArg1 = "this is my argument";
myClass.MyMethod(myArg1);
静若繁花 2024-07-12 18:31:19

参数是函数声明中的变量。

参数是传递给函数的该变量的实际值。

Parameter is the variable in the declaration of the function.

Argument is the actual value of this variable that gets passed to the function.

撩人痒 2024-07-12 18:31:19

简单:

  • PARAMETER → PLACEHOLDER (这表示占位符属于函数命名并在函数体中使用)
  • ARGUMENT → < Strong>ACTUAL VALUE(这意味着函数调用传递的实际值)

Simple:

  • PARAMETER → PLACEHOLDER (This means a placeholder belongs to the function naming and be used in the function body)
  • ARGUMENT → ACTUAL VALUE (This means an actual value which is passed by the function calling)
想你只要分分秒秒 2024-07-12 18:31:19

参数是函数声明中的变量。

参数是传递给函数的变量的实际值。

图像代码示例。函数 sum 接受参数 param1 和 param2。它返回 param1 加上 param2。使用参数 5 和 6 调用函数 sum。该图像指出 param1 和 param2 是参数,而 5 和 6 是参数。< /a>

A parameter is a variable in the declaration of the function.

An argument is the actual value of the variable that gets passed to the function.

Image of a code sample. Function sum takes parameters param1 and param2. It returns param1 plus param2. The function sum is called with the arguments 5 and 6. The image points out that param1 and param2 are parameters, whereas 5 and 6 are arguments.

浪推晚风 2024-07-12 18:31:19

已经有一个关于该主题的维基百科条目(请参阅参数),它定义并区分了术语参数参数。 简而言之,参数是函数/过程/方法签名的一部分,参数是在运行时和/或调用站点为参数提供的实际值。

维基百科文章还指出,这两个术语经常同义词使用(特别是在非正式地推理代码时):

虽然参数也很常见
称为论证、论证
更恰当地被认为是
实际值或指定的参考值
到参数变量时
子例程在运行时调用。

假设以下 C 语言示例函数将两个整数相加,xy 将被称为其参数:

int add(int x, int y) {
    return x + y;
}

在调用站点使用 add,如下所示的示例,123456 将被称为调用的参数

int result = add(123, 456);

此外,某些语言规范(或正式文档)选择专门使用参数参数,并使用诸如正式实际之类的形容词em> 来消除两种情况之间的歧义。 例如,C/C++ 文档通常将函数参数称为形式参数,将函数调用参数称为实际参数 。 有关示例,请参阅 形式和实际参数” href="http://msdn.microsoft.com/en-us/library/3bstk3k5.aspx" rel="noreferrer">Visual C++ 语言参考。

There is already a Wikipedia entry on the subject (see Parameter) that defines and distinguishes the terms parameter and argument. In short, a parameter is part of the function/procedure/method signature and an argument is the actual value supplied at run-time and/or call-site for the parameter.

The Wikipedia article also states that the two terms are often used synonymously (especially when reasoning about code informally):

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 runtime.

Given the following example function in C that adds two integers, x and y would be referred to as its parameters:

int add(int x, int y) {
    return x + y;
}

At a call-site using add, such as the example shown below, 123 and 456 would be referred to as the arguments of the call.

int result = add(123, 456);

Also, some language specifications (or formal documentation) choose to use parameter or argument exclusively and use adjectives like formal and actual instead to disambiguate between the two cases. For example, C/C++ documentation often refers to function parameters as formal arguments and function call arguments as actual arguments. For an example, see “Formal and Actual Arguments” in the Visual C++ Language Reference.

梦中楼上月下 2024-07-12 18:31:19

参数是调用函数时必须填写的内容。 你放进去的就是论证。

简单设置一下:argument 进入参数,argument 就是参数的值。

更多信息:
http://en.wikipedia.org/wiki/Parameter_(computer_science)#Parameters_and_arguments

A parameter is something you have to fill in when you call a function. What you put in it is the argument.

Simply set: the argument goes into the parameter, an argument is the value of the parameter.

A bit more info on:
http://en.wikipedia.org/wiki/Parameter_(computer_science)#Parameters_and_arguments

虫児飞 2024-07-12 18:31:19

假设您是一家航空公司。 你建造一架飞机。 你在里面安装座位。 然后,你把飞机装满乘客,然后把它送到某个地方。 乘客下船。 第二天,您再次使用同一架飞机和相同的座位,但这次搭载了不同的乘客。

飞机是你的职责。

参数是座位。

争论的焦点是坐在这些座位上的乘客。

function fly(seat1, seat2) {
    seat1.sayMyName();
    // Estraven
    seat2.sayMyName();
    // Genly Ai
    etc.
}

var passenger1 = "Estraven";
var passenger2 = "Genly Ai";

fly(passenger1, passenger2); 

Let's say you're an airline. You build an airplane. You install seats in it. Then, you fill the plane up with passengers and send it somewhere. The passengers disembark. Next day, you re-use the same plane, and same seats, but with different passengers this time.

The plane is your function.

The parameters are the seats.

The arguments are the passengers that go in those seats.

function fly(seat1, seat2) {
    seat1.sayMyName();
    // Estraven
    seat2.sayMyName();
    // Genly Ai
    etc.
}

var passenger1 = "Estraven";
var passenger2 = "Genly Ai";

fly(passenger1, passenger2); 
无名指的心愿 2024-07-12 18:31:19

参数和参数这两个术语的使用被误用了
在某种程度上,程序员甚至作家之间也存在这种情况。 当处理
方法中,术语参数用于标识占位符
方法签名,而术语参数是实际的
您传递给该方法的值。

MCSD 认证工具包(考试 70-483)C# 编程,第一版,Wrox,2013

真实案例场景

// Define a method with two parameters
int Sum(int num1, int num2)
{
   return num1 + num2;
}

// Call the method using two arguments
var ret = Sum(2, 3);

The use of the terms parameters and arguments have been misused
somewhat among programmers and even authors. When dealing with
methods, the term parameter is used to identify the placeholders in
the method signature, whereas the term arguments are the actual
values that you pass in to the method.

MCSD Cerfification Toolkit (Exam 70-483) Programming in C#, 1st edition, Wrox, 2013

Real-world case scenario

// Define a method with two parameters
int Sum(int num1, int num2)
{
   return num1 + num2;
}

// Call the method using two arguments
var ret = Sum(2, 3);
零度℉ 2024-07-12 18:31:19

一般来说,术语参数和实参可互换使用,表示传递到函数中的信息。

然而,从函数的角度来看:

  • 参数是函数定义中括号内列出的变量。
  • 参数是调用函数时发送到该函数的值。

Generally speaking, the terms parameter and argument are used interchangeably to mean information that is passed into a function.

Yet, from a function's perspective:

  • A parameter is the variable listed inside the parentheses in the function definition.
  • An argument is the value that is sent to the function when it is called.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文