In C programming, the terms formal arguments and actual arguments refer to the parameters involved in a function call and definition.
Formal Arguments (Formal Parameters):
Formal arguments are the variables declared in the function's definition or prototype. They act as placeholders for the values that will be passed to the function when it is called. These arguments define the type and name of the data the function expects to receive.
Actual Arguments (Actual Parameters):
Actual arguments are the values or expressions that are passed to a function when it is called. These are the "real" values that the function will operate on. Actual arguments can be constants, variables, expressions, or even the results of other function calls.
Example in C:
Explanation:
- Formal Arguments: In the add function definition int add(int a, int b), a and b are the formal arguments. They specify that the add function expects two integer values as input.
- Actual Arguments:
- In the first function call int sum = add(x, y);, x and y are the actual arguments. The values stored in x (10) and y (20) are passed to the add function.
- In the second function call int result = add(5, 7);, 5 and 7 are the actual arguments. These literal values are directly passed to the add function.
When add(x, y) is called, the value of x (10) is copied into the formal argument a, and the value of y (20) is copied into the formal argument b. The add function then performs its operation using these copied values. The same process occurs when add(5, 7) is called, with 5 being copied to a and 7 to b.
