Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   What is the difference between argument and parameter in C++? (http://www.velocityreviews.com/forums/t610033-what-is-the-difference-between-argument-and-parameter-in-c.html)

puzzlecracker 04-14-2008 02:12 PM

What is the difference between argument and parameter in C++?
 
C++ standard says the following:

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

Thanks,

puzzlecracker

Barry 04-14-2008 02:23 PM

Re: What is the difference between argument and parameter in C++?
 
On Apr 14, 10:12*pm, puzzlecracker <ironsel2...@gmail.com> wrote:
> 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

Barry 04-14-2008 02:34 PM

Re: What is the difference between argument and parameter in C++?
 
On Apr 14, 10:23*pm, Barry <dhb2...@gmail.com> wrote:
> On Apr 14, 10:12*pm, puzzlecracker <ironsel2...@gmail.com> wrote:
>
> > 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
:-)


Barry 04-14-2008 02:45 PM

Re: What is the difference between argument and parameter in C++?
 
On Apr 14, 10:32*pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
> Barry wrote:
> > On Apr 14, 10:12 pm, puzzlecracker <ironsel2...@gmail.com> wrote:
> >> 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



Pascal J. Bourguignon 04-14-2008 03:39 PM

Re: What is the difference between argument and parameter in C++?
 
Barry <dhb2000@gmail.com> writes:
> 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__


All times are GMT. The time now is 05:30 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57