What is the difference between formal parameters and actual parameters in C language?

王林
Release: 2020-05-31 13:20:28
Original
8126 people have browsed it

What is the difference between formal parameters and actual parameters in C language?

The differences between formal parameters and actual parameters in C language are:

1. Formal parameter variables will only allocate memory when the function is called. After the call is completed, The memory is released immediately, so the formal parameter variables are only valid inside the function and cannot be used outside the function.

2. Actual parameters can be constants, variables, expressions, functions, etc. No matter what type of data the actual parameters are, they must have certain values ​​when making function calls, so that these values is transferred to the formal parameter, so assignment, input, etc. should be used in advance to obtain a definite value for the actual parameter.

3. The actual parameters and formal parameters must be strictly consistent in number, type, and order, otherwise a "type mismatch" error will occur. Of course, if automatic type conversion is possible or forced type conversion is performed, the actual parameter type can also be different from the formal parameter type.

4. The data transfer that occurs in function calls is one-way. The value of the actual parameter can only be transferred to the formal parameter, but the value of the formal parameter cannot be transferred to the actual parameter in the reverse direction; in other words , once the data transfer is completed, the actual parameters and the formal parameters have nothing to do with each other. Therefore, during the function call process, the change in the value of the formal parameter will not affect the actual parameters.

5. Although the formal parameters and actual parameters can have the same name, they are independent of each other and do not affect each other, because the actual parameters are valid outside the function, while the formal parameters are valid inside the function.

Recommended tutorial: c language tutorial

The above is the detailed content of What is the difference between formal parameters and actual 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