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

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

声明一下,我是自学的,没有计算机科学的背景。(请不要让我去读《代码完成》,因为我这么做是为了让那些还没有史蒂夫·麦康奈尔这本了不起的书的人受益。)

总结

普遍的共识似乎是,在团队环境中可以互换使用这些术语。除非你在定义精确的术语;然后你也可以使用“正式参数/参数”和“实际参数/参数”来消除歧义。


当前回答

函数的形式形参在函数声明中列出,并在函数定义的主体中使用。形式形参(任何类型的)是一种空白或占位符,在调用函数时用一些东西填充。

实参是用来填充形式形参的。当你写下一个函数调用时,实参会在函数名后面的括号中列出。在执行函数调用时,将插入形式形参的实参。

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.

其他回答

考虑下面的java代码。

public class Test{
   public String hello(String name){
      return "Hello Mr."+name;
   }

  public static void main(String args[]){
     Test test = new Test();
     String myName = "James Bond";
     test.hello(myName);
  }
}

hello(String name)的方法定义声明了一个名为name的String参数。 在main方法中,我们通过传入参数myName来调用hello方法。

parameter是占位符,而argument是方法的实际值。

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

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

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

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;
}

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

public void MyMethod(string myParam) { }

...

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

参数是函数接收到的变量。因此,它们在函数声明中可见。它们包含变量名及其数据类型。 参数是传递给另一个函数的实际值。这就是为什么我们可以在函数调用中看到它们。它们只是没有数据类型的值