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

后端 未结 30 1869
北恋
北恋 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条回答
  • 2020-11-22 01:57

    Parameter is variable in the declaration of function.

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

    0 讨论(0)
  • 2020-11-22 01:57

    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).
    0 讨论(0)
  • 2020-11-22 01:57

    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.

    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.

    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.

    0 讨论(0)
  • 2020-11-22 01:58

    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);
    
    0 讨论(0)
  • 2020-11-22 01:59

    Parameters are the variables received by a function.Hence they are visible in function declaration.They contain the variable name with their data type. Arguments are actual values which are passed to another function. thats why we can see them in function call. They are just values without their datatype

    0 讨论(0)
  • 2020-11-22 02:01

    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.

    0 讨论(0)
提交回复
热议问题