+ 3
parameter and argument
what is the difference between parameter and argument?
4 Respuestas
+ 6
Parameters are part of function signature, specified in function declaration. In the following example <a> and <b> are parameters.
int add(int a, int b)
{
return a + b;
}
Arguments are the things we pass to the function when we call them. In the following example 20 and 22 are arguments:
int result = add(20, 22);
Hth, cmiiw
+ 4
EDIT: i didn't read all replies but i'm pretty sure that everyone literally said the same as i said and even more detailed, but atleast you now have multiple of replies to get it better.
An example from python:
def func(x):
return x+2
func(4) "outputs 6"
-the x is a parameter
-4 is an argument 'the value that replaces the original parameter'
+ 3
parameter == box
argument == what you put in there
+ 2
Argument is what we pass currently to the function (variable, pointer, array ). Parameter is what we need to call function, parameter can be alleged. It means can be initialized with some value when we call function without an argument .For example:
int func(int param1, int param2);
/*declaration of the function with two parameters*/
int x= 5; // actual argument
int y= 8; // also actual argument
// now will be called function
func( x , y ); /* now function use two actual arguments and inside it's body execute some code with two formal arguments to compute and return value*/
// body of called function above
func(int param1, int param2){
int sum= param1 +param2;
return sum;
}
/* param1 and param2 inside the body function are formal arguments. Inside we work on copies of arguments not on actual arguments so that's why function "func" must change names.*/