views:

159

answers:

4

is there a difference between a parameter and an argument, or are they simply synonyms?

+24  A: 

Argument is often used in the sense of "actual argument" vs. "formal parameter".

The formal parameter is what's given in the function declaration/definition/prototype, the actual argument is what's passed when calling the function, an instance of a formal parameter, if you will.

That being said, they're often used interchangably, or depending on language/community, and I've also heard "actual parameter" &c.

So here, x and y would be formal parameters:

int foo(int x, int y) {
    ...
}

Whereas here, in the function call, 5 and z are the actual arguments:

foo(5, z);
danlei
Jake Petroules
danlei
+6  A: 

Generally, the parameters are what are used inside the function and the arguments are the values passed when the function is called. Unless you take the opposite view.

double sqrt(double x)
{
    ...
    return x;
}

void other(void)
{
     double two = sqrt(2.0);
}

Under my thesis, x is the parameter to sqrt() and 2.0 is the argument.

The terms are often used at least somewhat interchangeably.

Jonathan Leffler
+1  A: 

They are often used interchangeably in text, but in most standards the distinction is that an argument is an expression passed to a function, where a parameter is a reference declared in a function declaration.

Alex M.
A: 

Depends on what is the context of the question. If this is about C++ standard, yes they have different definitions in the standard.

tdobek