Table of Contents
Function arguments are the values supplied to a function when it is called. The arguments are matched with the function’s parameters in their corresponding order.
The number, order, and types of arguments must be compatible with the function’s parameter list. Arguments provide the actual data that a function uses during its execution.
Source Code #
#include <iostream>
int add(int first, int second)
{
return first + second;
}
int main()
{
int result = add(15, 25);
std::cout << "Sum: " << result << '\n';
return 0;
}
Output #
Sum: 40
Explanation #
15and25are the function arguments supplied whenadd()is called.add(15, 25)passes the first argument to the parameterfirstand the second argument tosecond.- Arguments are associated with parameters according to their position in the function call.
- The first argument corresponds to the first parameter, and the second argument corresponds to the second parameter.
- The function parameters
firstandsecondreceive the supplied argument values. - The function uses these values to calculate and return their sum.
- A function call must provide arguments that are compatible with the corresponding parameter types.
- Arguments are specified at the point where the function is called, while parameters are declared as part of the function definition.
return 0;terminates the program successfully.