-
There are the following differences:1. The main body is different: When the argument is called, the parameter in parentheses after the function name is "actual parameter". Parameters are not actual variables, also known as dummy variables.
2. Different purposes: Arguments can be constants, variables, or expressions, and no matter what type of quantity the arguments are, they must have definite values when making a function call, so that these values can be transmitted to the parameters.
It should be noted that when the parameters and arguments are not pointer types, when the function is running, the arguments and arguments are different variables, they are located in different positions in memory, and the arguments make a copy of the content of the arguments, and the arguments are released at the end of the function, while the arguments do not change.
-
Parameters appear in the function definition and can be used throughout the function, but cannot be used outside the function. The arguments appear in the tonal function, and the arguments cannot be used after entering the modulated function. The function of the form and the actual parameters is to transmit data.
When a function is called, the tonal function transmits the value of the real argument to the shape parameter of the modulated function, so that the data of the tonal function is transmitted to the modulated function.
1. The parameter variable allocates the memory unit only when it is called, and at the end of the call, the allocated memory unit is released immediately. Therefore, arguments are only valid inside the function. After the function call is completed, the key function can no longer be used.
2. Arguments can be constants, variables, expressions, functions, etc., no matter what type of quantities the arguments are, they must have definite values when making a function call, so that these values can be transmitted to the parameters. Therefore, the parameters should be assigned and input in advance to obtain a definite value.
3. The actual parameters and the form parameters should be strictly consistent in terms of quantity, type and order, otherwise the error of "type mismatch" will occur.
4. The data transfer that occurs in the function call is one-way. That is, the value of the argument can only be transmitted to the parameter, and the value of the argument cannot be transmitted to the argument in reverse. Therefore, during the function call, the value of the parameter changes, but the value of the argument does not.
-
The parameter appears in the function definition and can be applied to all implication bodies, but not without the function. The arguments appear in the main style function, and the arguments cannot be applied after entering the modulated function.
The function of the form parameter and the real parameter is to transmit data information. When the call function is generated, the main style function transmits the value of the real argument to the shape parameter of the modulated function, and then completes the data information transmission from the main style function to the modulated function.
The parameter variable allocates the memory module only when it is enabled, and when it is enabled, the assigned running memory module is immediately released. Therefore, the form parameter is only reasonable within the connotation. After calling the function and returning to the main style function, you cannot apply the parameter variable.
Arguments can be variable definitions, independent variables, relations, functions, etc., and no matter what kind of quantity the arguments are, they must have a clear value when calling the function, so that the value can be transmitted to the form argument. Therefore, it is necessary to use methods such as taking values and typing in advance to obtain clear values for the arguments. The order of the actual parameters and the form parameters should be strictly consistent in terms of the total number and types, otherwise there will be an incorrect "type mismatch".
-
Parameters: The full name of "formal parameters" is the parameter used when defining the function name and function body, and is used to receive the parameters passed when the function is called.
The function of the form parameter is to realize the connection between the main tone function and the modulated function, and usually the data processed by the function, the factors affecting the function of the function or the result of the function processing are used as the form parameters. Functions without parameters should be written at the position of the parameter table Functions can also have parameters and return values, and their parameters, also known as command line arguments, are initialized by the operating system when the program is started, and its return value is passed to the operating system.
Arguments: They can be constants, variables, expressions, functions, etc., and no matter what type of arguments they are, they must have definite values when making a function call in order to pass these values to the parameters. Therefore, the parameters should be assigned and input in advance to obtain a definite value.
The difference between real and form parameters:
Blank space or placeholders.
1。The formal parameters of a function are listed in the function declaration and are used in the body of the function defined by the function. When a function is called, a parameter (of any kind) is a type of blank space or placeholder that will be filled.
It is used to fill in the form parameters.
2。The actual parameters are used to fill in the form parameters. When a function is called, the arguments are listed in parentheses after the function name. When a function call is executed, the argument is passed to the parameter.
Value-based calls and reference calls.
3。Value-based and reference-based calls refer to a mechanism used in the process of passing parameters. In the value transfer call, only the values of the arguments are used.
In the value transfer mechanism, the form parameter is a local variable, and its initial value is the value of the corresponding argument. In the referencing mechanism, the address of the argument is passed to the argument, which ostensibly replaces the argument with the argument, so any change that occurs on the argument actually happens on the argument.
-
In layman's terms, the parameters are the variables of the parameter table when the function is defined, and the arguments are the variables (written in parentheses after the function name) given to the function when the function is called
-
It doesn't matter what the shape is or what the parameters are, just remember how to use them.
Actually, I can't tell the difference, hehe.
When calling a function, there are two places where you need parameters.
One is when defining a function.
As. int fan(int a,int b) There is a parameter here, that is, ab This is the form parameter.
Generally speaking, you have to get used to writing the ** that implements the function in front of main, so that you don't have to define the function anymore, and there is one less line**, hehe.
The other is when it's called.
As. main
This is how the two parameters, the real parameter and the form parameter, are used.
Pay attention to a few points. 1. The real parameter and the form parameter can use the same variable name, or they can be different, and it is recommended to be different (easy to distinguish).
2. When calling, the form parameter needs to apply for memory space separately. Therefore, changing the value of a variable in a subfunction has no effect on the variables in the main function.
There are two exceptions, one is to define the parameter with &, and the other is to use the array as the parameter. In fact, it is a truth, that is, the memory address is used as a parameter, because the array name is a pointer address.
3. The scope of the variable, this is when the name of the variable in the subfunction is the same as the name of the variable in the global variable or the main function, then the variable in the subfunction only plays a role in the subfunction, and the memory space occupied by this variable will be cancelled after the call. The reason is that although the name is the same, when compiled to binary**, the memory space it occupies is different.
-
* 3 and 4 are the real parameters, a and b are the form parameters, the real parameters are the actual parameters, the form parameters are the formal parameters, * the formal parameters need to be assigned by the actual parameters. In other words, when calling a function, you need to have a real argument.
function apublic void show(int a, int b).
Invoke. show(3,4);
-
When defining a function, the name of the variable in parentheses after the function name is "formal parameter" (abbreviation: form parameter).
When a function is called in a tonal function, the argument in parentheses (which can be an expression) after the function name is called the "actual parameter" ("argument" for short).
-
One is the variable value and the other is the specific value.
-
Parameters and arguments appear in function calls.
-
The remaining parameters defined in the function are the real arguments.
-
Parameters and arguments are data transfersWhen a function is called, the tonal function transmits the value of the real argument to the shape parameter of the modulated function, so that the data of the tonal function is transmitted to the modulated function. Arguments: They can be constants, variables, expressions, functions, etc., and no matter what type of arguments they are, they must have definite values when making a function call in order to pass these values to the parameters.
The difference between a form parameter and a real ginsengThe parameter is a variable used to receive the parameter value when the function is called, and it is a parameter used when defining the function name and function body, and the purpose is to receive the parameter passed in when the function is called.
The data transmission that occurs in the function call is one-way, that is, only the value of the argument can be transmitted to the argument, and the value of the argument cannot be transmitted to the argument in reverse, so the value of the argument changes during the function call, but the value of the argument does not change.
-
The distinction is made by the position of the form in the function, and the difference between the two is as follows:
First, the subject is different.
1. Arguments: When calling a function with parameters, the parameter in parentheses after the function name is "actual argument".
2. Form parameters: not actual variables, also known as virtual variables.
Second, the purpose is different.
1. Arguments: They can be constants, variables, or expressions, no matter what type of arguments they are, they must have definite values when calling the function, so that these values can be transmitted to the parameters.
2. Parameters: The parameters used when defining the function name and function body, the purpose of which is to receive the parameters passed in when the function is called.
Third, the characteristics are different.
1. Arguments: In the process of calling the function, the system will pass the value of the argument to the form argument of the called function. In other words, the form parameter gets a value from the actual argument. The value is valid for the duration of the function call and can participate in operations in the function.
2. Form Parameter: The essence of Form Parameter is a name, which does not occupy memory space.
To change the value of a variable by passing a function, you must pass an address. Your program is passing the value of the variable swap(a,b); If you want to change the value of a variable, you must pass the address of the variable, or do it by a pointer, if it is an array, you can directly use the array name, but if it is an element of the array, you still need to use the address. Just change it like the one upstairs did him. >>>More
Program 1 can realize the exchange of a and b values, but program 2 does not. To understand this, you need to know a few things: >>>More
The address assigned to the parameter and the parameter is different. >>>More
Actually, you can understand the problem this way, int
a=1,b=2;It can be seen that a, b are real arguments, and 1 and 2 are form arguments, so when calling the function swap(a,b), the form arguments are passed, that is, 1 and 2 are passed, not a and b are passed. then swap(a,b) is swap(1,2). >>>More
What is the difference between the social security paid by urban residents and urban employees?