- In C, actual arguments are the values or expressions passed to a function when it is called.
- Actual arguments are used to provide input to the function and can be of different types depending on the function’s parameter requirements.
Here’s an example that demonstrates the use of actual arguments:
C
#include <stdio.h>
// Function that calculates the sum of two numbers
int add(int a, int b) {
return a + b;
}
int main() {
int num1 = 10;
int num2 = 5;
// Call the add() function with actual arguments num1 and num2
int result = add(num1, num2);
printf("The sum of %d and %d is: %d\n", num1, num2, result);
return 0;
}
Explanation:
In this example, the add() function takes two integer parameters, a and b. In the main() function, we declare two variables num1 and num2 and assign them the values 10 and 5, respectively.
When we call the add() function, we pass the actual arguments num1 and num2. The values of num1 and num2 are copied into the corresponding function parameters a and b. The function then performs the addition operation using these values and returns the result.
The result is stored in the result variable, and we print the sum using printf().
Output:
Output
The sum of 10 and 5 is: 15