Formal parameters are parameters declared in the function definition and receive the input of the function; actual parameters are the actual values passed when calling the function. In C language, a value transfer mechanism is used between formal parameters and actual parameters, that is, the value of the actual parameter is copied to the formal parameter without modifying the value of the actual parameter itself. The type of formal parameters can be declared as any data type, and the number and type of actual parameters must be consistent with those in the function definition.
Formal parameters and actual parameters: Basic concepts of C language
What are formal parameters and actual parameters ?
In C language, formal parameter and actual parameter are two closely related concepts:
The relationship between formal parameters and actual parameters
When calling a function, the value of the actual parameter will be assigned to the corresponding formal parameter, so that inside the function use. Therefore, the role of formal parameters is to receive the values of actual parameters and make these inputs accessible within the function.
Type of formal parameters
Formal parameters can be declared as any data type, including basic data types, structures, pointers, etc.
Value passing
In C language, the value passing mechanism is used between formal parameters and actual parameters. This means that the value of the actual parameter is copied into the formal parameter, but the value of the actual parameter itself is not modified.
Example
The following is an example of a C language function that receives two formal parameters:
<code class="c">void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; }</code>
In this function, the formal parametersa
and b
point to two integer variables respectively. When the function is called, the values of the actual parameters are assigned to a
and b
, thus exchanging the values of the two integers within the function.
Note:
The above is the detailed content of What do formal parameters and actual parameters mean in C language?. For more information, please follow other related articles on the PHP Chinese website!