In function calls, the actual and formal parameters correspond one-to-one, and the actual parameter values are copied to the formal parameters, following the value transfer principle. Ausnahme: The array type actual parameter is passed the starting address, and the formal parameter modification will affect the actual parameter group elements.
The relationship between actual parameters and formal parameters in C language
The actual parameters and formal parameters are in the process of function calling Two closely related concepts.
Definition
Relationship
There is a one-to-one relationship between actual parameters and formal parameters. When a function is called, each actual parameter corresponds to a formal parameter and is assigned a value.
Role
Formal parameters act as local variables inside the function, used to store the actual data provided by the actual parameters. Actual parameters are passed to the function through formal parameters, allowing the function to operate on data provided by the caller.
Value passing
The method of passing function parameters in C language is value passing. This means that the value of the actual parameter is copied into the formal parameter, rather than directly referencing the memory address of the actual parameter. Therefore, changes to the formal parameters do not affect the actual parameters.
Exceptions
For array type parameters, since the array is a reference type, the actual parameter passed to the formal parameter is the starting address of the array element. Therefore, modifications to the formal parameters directly affect the corresponding array elements in the actual parameters.
Note
The above is the detailed content of The relationship between actual parameters and formal parameters in C language. For more information, please follow other related articles on the PHP Chinese website!