What's the difference between an argument and a parameter?

后端 未结 30 1862
北恋
北恋 2020-11-22 01:08

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

30条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 01:44

    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.

提交回复
热议问题