Actual vs Formal Parameters
In computer programming, actual parameters and formal parameters refer to the arguments passed to a function and the parameters declared in the function signature, respectively.
Actual parameters are the values that are passed to a function when it is called. For example:
int result = add(2, 3);
In this example, the actual parameters passed to the add
function is 2
and 3
.
Formal parameters are the parameters declared in the function signature. For example:
int add(int x, int y) {
return x + y;
}
In this example, the formal parameters of the add
the function is x and y, both type int
.
The actual parameters are matched to the formal parameters in the order in which they are declared. In the example above, the actual parameter 2
is matched to the formal parameter x
, and the actual parameter 3
is matched to the formal parameter y
.
It is important to note that the values of the actual parameters are not directly accessible in the function body. Instead, the values of the actual parameters are passed to the function and are assigned to the corresponding formal parameters.
Overall, the distinction between actual and formal parameters is an important aspect of function calling in computer programming. Understanding the difference between actual and formal parameters can help you write more clear and more accurate code.