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

后端 未结 30 1864
北恋
北恋 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: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.

提交回复
热议问题