Definition: Arguments are values or variables used to pass information to a function. In C, arguments used in the function definition are called formal parameters, while the values or variables supplied during the function call are called actual arguments.
Definition: Arguments are values or variables used to pass information to a function. In C, arguments used in the function definition are called formal parameters, while the values or variables supplied during the function call are called actual arguments.
add(x, y), x and y used
in the function call are actual arguments. In
int add(int a, int b), a and b
are formal parameters.
Definition: Formal parameters are variables written in the function definition that receive values from the function call.
int add(int a, int b), a and
b are formal parameters.
int add(int a, int b)
{
return a + b;
}
Definition: Actual arguments are the values or variables supplied when a function is called.
add(10, 20), 10 and 20
are actual arguments.
int result = add(10, 20);
| Formal Parameters | Actual Arguments |
|---|---|
| Written in the function definition. | Written in the function call. |
| Receive the values passed to the function. | Provide values to the function. |
Example: a, b |
Example: 10, 20 |
| They are variables. | They can be constants, variables or expressions. |
Definition: During a function call, actual arguments are matched with the corresponding formal parameters according to their position.
add(10, 20), 10 is passed to
a and 20 is passed to b.
int add(int a, int b)
{
return a + b;
}
add(10, 20);
The order of actual arguments is important because each argument corresponds to the formal parameter in the same position.
subtract(10, 5) is different from
subtract(5, 10) because the values are passed in
a different order.
The number of supplied arguments should correspond to the parameters expected by the function call, subject to the function's declaration and language rules.
int add(int a, int b), it expects two integer arguments,
such as add(10, 20).
Actual arguments do not have to be fixed numbers. Variables can also be passed to a function.
add(x, y) passes the current values of
x and y.
An expression can also be supplied as an actual argument. The expression is evaluated and its resulting value is passed to the function.
add(x + 5, y * 2), the two expressions are evaluated
and their values are passed to the function.
#include <stdio.h>
int multiply(int a, int b) // a and b are formal parameters
{
return a * b;
}
int main()
{
int x = 5;
int y = 4;
int result = multiply(x, y); // x and y are actual arguments
printf("Result = %d
", result);
return 0;
}
Result = 20
Write a C program that accepts two integers and passes them to a user-defined function to calculate their sum.
Create an add() function with two formal parameters.
Pass two variables from main() as actual arguments.
Formal parameters appear in the function definition and receive values from the corresponding actual arguments supplied during the function call.
#include <stdio.h>
int add(int a, int b); // a and b are formal parameters
int main()
{
int x, y, result;
printf("Enter two numbers: ");
scanf("%d %d", &x, &y);
result = add(x, y); // x and y are actual arguments
printf("Sum = %d
", result);
return 0;
}
int add(int a, int b)
{
return a + b; // calculate and return the sum
}
Enter two numbers: 10 25 Sum = 35
Here, x and y are actual arguments in the
function call, while a and b are formal
parameters in the function definition.
| Term | Remember | Example |
|---|---|---|
| Formal Parameter | Receives the value. | a, b |
| Actual Argument | Provides the value. | 10, 20 |
| Function Definition | Contains formal parameters. | add(int a, int b) |
| Function Call | Contains actual arguments. | add(10, 20) |
Watch a beginner-friendly explanation of formal and actual arguments in C.
A short handwritten-style revision sheet for formal and actual arguments will be provided here.
Use the mind map for quick revision of function calls, formal parameters and actual arguments.