Argument
An argument is a reference to the values passed in a function when the function is called. These values are often the source of a function that requires arguments during execution. These values are assigned to variables in the definition of the called function. The types of the values passed into the function are the same as the types of the variables specified in the function definition. They are also known as actual arguments or actual parameters.
For example, suppose a function needs to be called sum() with two numbers to add. These two numbers are called arguments and are passed to sum() when it is called from somewhere else.
C
// C code to illustrate Arguments
#include
// sum: Function definition
int sum(int a, int b)
{
// returning the addition
return a + b;
}
// Driver code
int main()
{
int num1 = 10, num2 = 20, res;
// sum() is called with
// num1 & num2 as ARGUMENTS.
res = sum(num1, num2);
// Displaying the result
printf("The summation is %d", res);
return 0;
}
C++
// C++ code to illustrate Arguments
#include
using namespace std;
// sum: Function definition
int sum(int a, int b)
{
// returning the addition
return a + b;
}
// Driver code
int main()
{
int num1 = 10, num2 = 20, res;
// sum() is called with
// num1 & num2 as ARGUMENTS.
res = sum(num1, num2);
// Displaying the result
cout
Output:
The summation is 30
Parameter
Parameters are called variables defined in a function declaration or function definition. These variables are used to receive arguments passed during function calls. The parameters in the function prototype are applied to the execution of the function in which it is defined. They are also known as formal arguments or formal parameters.
For example, suppose a function needs to be defined Mult() to multiply two numbers. These two numbers are considered parameters and are defined while defining the function Mult().
C
// C code to illustrate Parameters
#include
// Mult: Function definition
// a and b are the PARAMETERS
int Mult(int a, int b)
{
// returning the multiplication
return a * b;
}
// Driver code
int main()
{
int num1 = 10, num2 = 20, res;
// Mult() is called with
// num1 & num2 as ARGUMENTS.
res = Mult(num1, num2);
// Displaying the result
printf("The multiplication is %d", res);
return 0;
}
C++
// C++ code to illustrate Parameters
#include
using namespace std;
// Mult: Function definition
// a and b are the parameters
int Mult(int a, int b)
{
// returning the multiplication
return a * b;
}
// Driver code
int main()
{
int num1 = 10, num2 = 20, res;
// Mult() is called with
// num1 & num2 as ARGUMENTS.
res = Mult(num1, num2);
// Displaying the result
cout
Output:
The multiplication is 200
Difference between Arguments and Parameters
Argument | Parameter |
---|---|
When a function is called, the values passed during the call are arguments. | The values determined at the time of function prototype or function definition are called parameters. |
They are used in function calls to send values from the calling function to the receiving function. | They are used in the header of the called function to receive values from the arguments. |
During call time, each argument is always assigned to a parameter in the function definition. | Parameters are local variables that are assigned the values of the arguments when the function is called. |
They are also known as Actual Parameters | They are also known as Formal Parameters |
For example:
|
For example:
|