By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,262 Members | 1,125 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,262 IT Pros & Developers. It's quick & easy.

What is the difference between argument and parameter in C++?

P: n/a
C++ standard says the following:

I am reading through c++ standard and have a difficulty understanding
the difference between these two terms.

Thanks,

puzzlecracker
Jun 27 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Apr 14, 10:12*pm, puzzlecracker <ironsel2...@gmail.comwrote:
C++ standard says the following:

I am reading through c++ standard and have a difficulty understanding
the difference between these two terms.
argument refers to "formal parameter"
parameter refers to "actual parameter"

void f(int argument) {}

int main()
{
int parameter;
f(parameter);
}
template <class ArgumentType>
void f() {
}

int main()
{
typedef int ParameterType;
f<ParameterType>();
}
HTH.

--
Best Barry
Jun 27 '08 #2

P: n/a
Barry wrote:
On Apr 14, 10:12 pm, puzzlecracker <ironsel2...@gmail.comwrote:
>C++ standard says the following:

I am reading through c++ standard and have a difficulty understanding
the difference between these two terms.

argument refers to "formal parameter"
parameter refers to "actual parameter"
IME it's vice versa. IOW, 'argument' is a run-time thing, defined by
the _caller_. And 'parameter' is what the function has, internally;
it's more or less abstract.

If you replace 'parameter' with 'argument' and leave 'argument' as is,
you will get the normal C++ terminology.
>
void f(int argument) {}

int main()
{
int parameter;
f(parameter);
}
template <class ArgumentType>
void f() {
}

int main()
{
typedef int ParameterType;
f<ParameterType>();
}
HTH.
Turn it around and it should.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #3

P: n/a
On Apr 14, 10:23*pm, Barry <dhb2...@gmail.comwrote:
On Apr 14, 10:12*pm, puzzlecracker <ironsel2...@gmail.comwrote:
C++ standard says the following:
I am reading through c++ standard and have a difficulty understanding
the difference between these two terms.

argument refers to "formal parameter"
parameter refers to "actual parameter"

void f(int argument) {}

int main()
{
* *int parameter;
* *f(parameter);

}

template <class ArgumentType>
void f() {

}

int main()
{
* *typedef int ParameterType;
* *f<ParameterType>();

}

Sorry, by checking the standard, I got them reversed
:-)

Jun 27 '08 #4

P: n/a
On Apr 14, 10:32*pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Barry wrote:
On Apr 14, 10:12 pm, puzzlecracker <ironsel2...@gmail.comwrote:
C++ standard says the following:
I am reading through c++ standard and have a difficulty understanding
the difference between these two terms.
argument refers to "formal parameter"
parameter refers to "actual parameter"

IME it's vice versa. *IOW, 'argument' is a run-time thing, defined by
the _caller_. *And 'parameter' is what the function has, internally;
it's more or less abstract.

If you replace 'parameter' with 'argument' and leave 'argument' as is,
you will get the normal C++ terminology.


void f(int argument) {}
int main()
{
* *int parameter;
* *f(parameter);
}
template <class ArgumentType>
void f() {
}
int main()
{
* *typedef int ParameterType;
* *f<ParameterType>();
}
HTH.

Turn it around and it should.
As I recall that code
often written as

int main(int argc, char* argv[]);

template <class Arg>
void f(Arg arg) {}

which are kinda misleading in recalling the difference between
argument and parameter.

--
Best Regards
Barry
Jun 27 '08 #5

P: n/a
Barry <dh*****@gmail.comwrites:
As I recall that code
often written as

int main(int argc, char* argv[]);

template <class Arg>
void f(Arg arg) {}

which are kinda misleading in recalling the difference between
argument and parameter.

Yes. You should consider:

int fun(int x,int y);
sin(3,42);

The parameters of the function fun are x and y.

The arguments of the function call on the second line are 3 and 42.
The argument 3 is assigned to the parameter x, and the argument 42 is
assigned to the parameter y.
We need to distinguish these qualifiers, to talk unambiguously about calls such as:

int gcd(int x,int y){
return((x==y)
?x
:((x<y)
?gcd(x,y-x)
:gcd(y,x-y)));
}

Where we can say that in the last call to gcd, the argument y is
passed to the parameter x, and the argument x-y is passed to the
parameter y.
Of course, since main takes as parameters the arguments given to the
program, we can name a parameter argument.

int f(int argument){
return((argument==1)
?1
:((argument%1)
?f(3*argument)
:f(argument/2)));
}

So we can say that the argument argument/2 is passed to the parameter
argument.

--
__Pascal Bourguignon__
Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.