Slider

Difference between Argument and Parameter.

A Parameter is a variable in the declaration and definition of the function. Argument is a actual value of the parameter that gets passed to the
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.


0

No comments

Post a Comment

both, mystorymag

DON'T MISS

Nature, Health, Fitness
© all rights reserved
made with by AlgoLesson
Table of Contents