Parameter 与argument有啥区别?

1870阅读 0评论2020-03-29 starb6
分类:PERL


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


Parameter 与argument有啥区别?



答:

———----------

Argument is often used in the sense of actual argument vs. formal parameter.


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.


So here, x and y would be formal parameters:

int foo(int x, int y) {

    ...

}

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

foo(5, z);


Argument 一般用作实际参数,而parameter 是概念性的。parameter是在定义的时候指定的参数,而argument 是实际带入这些参数的参数值。


比如 x 和 y 是参数parameters:

int foo(int x, int y) {

    ...

}

而实际调用时, 5 和 z 是 arguments:

foo(5, z);


—————-------------


Generally, the parameters are what are used inside the function and the arguments are the values passed when the function is called.

double sqrt(double x)

{

    ...

    return x;

}


void other(void)

{

     double two = sqrt(2.0);

}


Under my thesis, x is the parameter to sqrt() and 2.0 is the argument.







—————------------

They are often used interchangeably in text, but in most standards the distinction is that an argument is an expression passed to a function, where a parameter is a reference declared in a function declaration.

参考链接:






以一个 perl 实例为例:


构造函数里:

  my $ref={"Owner"=>$owner,

        "Price"=>$salary,

        "Style"=>$style,

    };


The key/value pairs are called the properties, or attributes, of the object. The values are passed in as arguments to the constructor.


实例方法(display)里:

    foreach $key( @_ )

    {

        print "$key: $$self{$key}\n";

    }



在主程序调用时:

$house->display(“Owner”,"Style");


The instance method is called with arguments.


上一篇:Perl 实例第四版笔记-第13章-引用
下一篇:MySQL 内链接