Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1148247
  • 博文数量: 286
  • 博客积分: 11086
  • 博客等级: 上将
  • 技术积分: 3245
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-22 17:06
个人简介

闻鸡起舞

文章分类

全部博文(286)

文章存档

2020年(9)

2019年(9)

2018年(6)

2017年(10)

2016年(10)

2014年(3)

2013年(4)

2011年(12)

2010年(16)

2009年(14)

2008年(125)

2007年(48)

2006年(20)

我的朋友

分类: PERL

2020-03-29 11:26:04


问: 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.


阅读(207) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~