The relationship between actual parameters and formal parameters in C language

下次还敢
Release: 2024-04-29 17:27:15
Original
1132 people have browsed it

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 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

  • Actual Arguments: The parameter value actually provided when calling the function.
  • Formal Arguments: Parameter variables declared in the function definition are used to receive actual parameters.

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 data types of actual parameters and formal parameters must be compatible.
  • The number and order of actual parameters must match the formal parameters.
  • Formal parameters can have default values, allowing actual parameters to be omitted when calling functions.

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template