C++ function parameters and arguments


C++ Function parameters and function arguments

What are parameters and arguments? , how are they related? and what is the difference between them? you will find the answers to these questions here.

While using functions we may want to pass some values to it because the function may require some values to execute it’s code,for instance if there is a function that can perform addition then the function will require some values to perform the addition .In such case the programmer has to pass some values such values which is passed when the function is called is known as arguments.And the arguments when received by the function is known as parameters. So parameter and arguments are the same values,they are given different names to simplify the identification of the error liable to be produced when values are passed to or received by the function (say error produced due to the passing of unmatched data type).The terms parameter and argument cannot be used interchangeably in C++.The program below shows the parameter and argument while calling a function.

#include <iostream>

using namespace std ;

void Circumference(float r) //’r’ is a parameter
{
cout << “Circumference of a circle with radius ” << r << ” is ” << 3.2425*r*r ;
}

int main()
{
float R=4.5 ;
Circumference(R) ; //R is an argument

cin.get() ;
return 0 ;
}

 


Related Link

->C++ Function:Declaration and definition.
 
->why is declaring or defining a function without the parameters names acceptable?