Difference between Argument and Parameter in C/C++ with Examples
Last Updated :
24 Jun, 2021
Argument
An
argument is referred to the values that are passed within a function when the function is called. These values are generally the source of the function that require the arguments during the process of execution. These values are assigned to the variables in the definition of the function that is called. The type of the values passed in the function is the same as that of the variables defined in the function definition. These are also called
Actual arguments or
Actual Parameters.
Example: Suppose a sum() function is needed to be called with two numbers to add. These two numbers are referred to as the arguments and are passed to the sum() when it called from somewhere else.
C
// C code to illustrate Arguments
#include <stdio.h>
// 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 <iostream>
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 << "The summation is " << res;
return 0;
}
Output:
The summation is 30
Parameters
The parameter is referred to as the variables that are defined during a function declaration or definition. These variables are used to receive the arguments that are passed during a function call. These parameters within the function prototype are used during the execution of the function for which it is defined. These are also called Formal arguments or Formal Parameters.
Example: Suppose a Mult() function is needed to be defined to multiply two numbers. These two numbers are referred to as the parameters and are defined while defining the function Mult().
C
// C code to illustrate Parameters
#include <stdio.h>
// 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 <iostream>
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 << "The multiplication is " << res;
return 0;
}
Output:
The multiplication is 200
Difference between Argument and Parameter
Argument |
Parameter |
When a function is called, the values that are passed during the call are called as arguments. |
The values which are defined at the time of the function prototype or definition of the function are called as parameters. |
These are used in function call statement to send value from the calling function to the receiving function. |
These are used in function header of the called function to receive the value from the arguments. |
During the time of call each argument is always assigned to the parameter in the function definition. |
Parameters are local variables which are assigned value of the arguments when the function is called. |
They are also called Actual Parameters |
They are also called Formal Parameters |
Example:
C
int num = 20;
Call(num)
// num is argument
|
Example:
C
int Call(int rnum)
{
printf("the num is %d", rnum);
}
// rnum is parameter
|
Similar Reads
Difference between int *a and int **a in C In C, the declarations int *a and int **a represent two different concepts related to pointers. Pointers play a fundamental role in memory management and data manipulation in C programming so it is important to have a clear understanding of them. What does int * means? This declares a pointer to an
3 min read
Difference between Identifiers and Variables in C Perquisites: Identifiers, Variables Identifiers Identifiers are used for the naming of variables, functions, and arrays. It is a string of alphanumeric characters that begins with an alphabet, or an underscore( _ ) that are used for variables, functions, arrays, structures, unions, and so on. It is
2 min read
Difference between Arrays and Pointers The array and pointers are derived data types that have lots of differences and similarities. In some cases, we can even use pointers in place of an array, and arrays automatically get converted to pointers when passed to a function. So, it is necessary to know about the differences between arrays a
7 min read
Difference between "int main()" and "int main(void)" in C/C++? Note: This was true for older versions of C but has been changed in C11 (and newer versions). In newer versions, foo() is same as foo(void). Consider the following two definitions of main(). Definition 1: C int main() { /* */ return 0; } C++ int main() { /* */ return 0; } Definition 2: C int main(vo
3 min read
Difference between Keyword and Identifier in C In C, keywords and identifiers are basically the fundamental parts of the language used. Identifiers are the names that can be given to a variable, function or other entity while keywords are the reserved words that have predefined meaning in the language.The below table illustrates the primary diff
3 min read