In C language, formal parameters are variables declared in the function definition and are used to receive data; actual parameters are the actual data passed to the function when the function is called. The formal parameter gets a copy of the actual parameter value, so modifications to the formal parameter do not affect the actual parameter and vice versa.
Formal parameters and actual parameters
In C language, formal parameters and actual parameters are two important Concepts that are used to pass data into functions.
Formal parameters
Actual parameters
Data passing
When the function is called, the actual parameters are passed to the formal parameters. The value of the formal parameter is obtained from the actual parameter by copying it. This means that any modifications to the formal parameters will not affect the values of the actual parameters and vice versa.
Purpose of formal parameters and actual parameters
Example
The following example demonstrates the use of formal parameters and actual parameters:
<code class="c">// 函数定义 int sum(int a, int b) { // a 和 b 是形参 return a + b; } // 函数调用 int result = sum(5, 10); // 5 和 10 是实参</code>
In the above example, a
and b
are the formal parameters of the function sum
, and 5
and 10
are the actual parameters when the function is called. The function returns 15
, which is the sum of the two arguments passed to the formal parameters a
and b
.
The above is the detailed content of What are formal parameters and actual parameters in C language?. For more information, please follow other related articles on the PHP Chinese website!