Key Difference – Argument vs Parameter
A function is an organized set of statements to perform a specific task. Functions are useful in repeating a piece of code, so they provide code reusability. Programming languages such as C language consist of built-in functions like printf(). It is also possible to write functions by the programmer. Those are called user-defined functions. Argument and Parameter are terms associated with functions. The key difference between argument and parameter is that an argument is the data passed at the time of calling a function while a parameter is a variable defined by a function that receives a value when the function is called. An argument is an actual value while a parameter is a placeholder.
CONTENTS
1. Overview and Key Difference
2. What is an Argument
3. What is a Parameter
4. Similarities Between Argument and Parameter
5. Side by Side Comparison – Argument vs Parameter in Tabular Form
6. Summary
What is an Argument?
In C programming language, the main() is a function. It indicates the starting point of the execution. Writing every statement in the main function can make the program very complex. It can be hard to test and debug. To overcome this problem, the main program can be divided into several functions or methods. Those functions can be called by the main program.
Declaration of a function in C language is as follows.
<return type> <function name> (<parameters>)
{
<function code>
}
The return type is the data type returned by the function. If the function returns a string, the return type is a “string”. If the function returns an integer, the return type is an “int”. If the function does not return anything, then that is declared as “void”. The function name can be named to identify what the function is about. It is the actual name of the function. Content to execute is inside a pair of curly braces. A simple example of a function is as follows.
void add() {
int a =10;
int b= 20;
printf(“sum is %d”, a+b);
}
To call this method, there should be a statement as add( ); in the main program. That will invoke the function.
Functions can be made more adaptable using arguments and parameters. Refer bellow piece of code.
void add(int a, int b){
printf(“sum is %d\n”, a+b);
}
void main(){
add(4,6);
add(5,2);
}
In the above code, values are passed from the main program to the function to calculate the sum.
In main, there is a statement add (4,6). 4 and 6 are the arguments. They are values that are passed to a function when it is invoked. In the main program, again there can be a statement as add (5,2). Now the arguments passed to the add function are 5 and 2. An argument is also called as an actual argument or actual parameter.
What is a Parameter?
A parameter is a variable defined by a function, that receives a value when a function is called. The parameter can also be known as a Formal parameter or formal argument. This concept can be easily understood by an example. Refer the bellow piece of code.
void multiply(int no1, int no2){
int multiply= no1 * no2;
printf(“Multiplication is %d\n “, multiply);
}
void main(){
multiply(2,3);
}
According to the above code, no1 and no2 in void multiply(int no1,int no2) are the parameters. They are the variables that are defined at the time, the function is called. Argument values go to the parameters when the function is created.
Refer the below program to calculate summation and subtraction of two numbers.
According to the above program, in calSum(a,b) , “a” and “b” are arguments.
int cal Sum(int a, int b) , a and b are parameters.
What is the Similarity Between Argument and Parameter?
- Argument and Parameter are related to functions.
What is the Difference Between Argument and Parameter?
Argument vs Parameter |
|
An argument is a value that is passed at the time of calling a function. | A parameter is a variable defined by a function that receives a value that when a function is called. |
Associated Function | |
An argument is passed by the calling function. | A parameter is in the called function. |
Summary – Argument vs Parameter
Functions are used to reduce the length of the source program. It is easy to do testing and debugging. Functions are also known as methods or sub-routines. It is possible to pass values to the function. Argument and parameter are associated with functions but they have different meanings. The difference between argument and parameter is an argument is a data passed at the time of calling a function and parameter is a variable defined by the function which receives a value when the function is called.
Download the PDF Version of Argument vs Parameter
You can download PDF version of this article and use it for offline purposes as per citation note. Please download PDF version here Difference Between Argument and Parameter
Reference:
1. Avelox. “Computer Programming for Beginners | Functions, Parameters & Arguments | Ep24”, YouTube, YouTube, 4 Apr. 2017. Available here
Leave a Reply