The difference between actual parameters and formal parameters in C language

下次还敢
Release: 2024-05-02 19:42:49
Original
468 people have browsed it

The actual parameters are the actual values passed when the function is called, while the formal parameters are placeholder variables declared in the function definition to receive the actual parameter values. The actual parameters are determined when calling, and the formal parameters are determined when defining; the actual parameters can be changed, but the formal parameters can only be modified within the function body.

The difference between actual parameters and formal parameters in C language

The difference between actual parameters and formal parameters in C language

In C language, the difference between actual parameters and formal parameters Parameters are two important concepts in function calls, and there are key differences between them.

Actual parameters

  • Actual parameters are the values or variables thatare actually passed to the function.
  • They appear inside parentheses when calling a function.
  • Actual parameters can be constants, variables, expressions or the function call itself.

Formal parameters

  • Formal parameters are placeholder variables declared infunction definition.
  • They appear as type and name in the function header.
  • When the function is called, the value of the actual parameter is passed to the corresponding formal parameter.

Difference

The main difference is:

  • The actual parameter is the actual value passed when the function is called, while the formal parameter is Placeholder used when defining functions.
  • The actual parameters are determined when the function is called, while the formal parameters are determined when the function is defined.
  • The actual parameters can be changed, but the formal parameters can only be used and modified within the function body.

Example

Consider the following function definitions:

int sum(int a, int b) { return a + b; }
Copy after login
  • aandbIt is a formal parameter and a placeholder variable.

When calling a function, the actual parameters are passed to the formal parameters:

int x = 5, y = 10; int result = sum(x, y);
Copy after login
  • xandyare actual parameters, use to actually pass to the function.
  • aandbwill receive the values ofxandyrespectively.

The above is the detailed content of The difference 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!