Difference between Argument and Parameter.

The two terms Parameters and Arguments are often used interchangeably while working on functions in programming but both the term have totally different meanings let's understand the difference between them.

Parameters

A Parameter is a variable in the declaration and definition of the function. The value of these variables is used inside the function to perform some computation on it and return us some output. The parameter is also known as Format Parameter.  

Example:
//C++ Example for Parameters
#include<iostream>
using namespace std;

//function definition
//x and y are two parameters
int add(int x, int y){
    return (x + y);
}
int main(){

    int m = 22, n = 8, sum;
    //function call
    sum = add(m, n);
    cout<<"SUM = "<<sum;

    return 0;
}
Output:
SUM = 30

Here add() function is defined with two parameters x and y and this function is used to perform addition of two numbers.

Arguments

Argument is a actual value of the parameter that gets passed to the function when the function is called.These values are passed to the function at the time of function call. They are also called as Actual Parameter.

Example:
//C++ Example for Arguments
#include<iostream>
using namespace std;

//function definition
int sub(int x, int y){
    return (x - y);
}
int main(){

    int m = 20, n = 8, diff;
    //function call
    //m and n are two arguments
    diff = sub(m, n);
    cout<<"Difference = "<<diff;

    return 0;
}
Output:
Difference = 12

Here sub() function is called with two argument value m and n and the task of this function is to perform the substraction of two numbers.


⚡ Please share your valuable feedback and suggestion in the comment section below or you can send us an email on our offical email id ✉ algolesson@gmail.com. You can also support our work by buying a cup of coffee ☕ for us.

Similar Posts

No comments:

Post a Comment


CLOSE ADS
CLOSE ADS