Home > Technology > Difference Between an Argument and a Parameter

Difference Between an Argument and a Parameter

The words argument and parameter are often used interchangeably in the literature, although the C++ Standard makes a clear distinction between the two.

An argument is one of the following:

  • an expression in the comma-separated list in a function call;
  • a sequence of one or more pre processor tokens in the comma-separated list in a macro call;
  • the operand of a throw-statement or an expression, type, or template-name in the comma-separated list in the angle brackets of a template instantiation.

A parameter is one of the following

  • an object or reference that is declared in a function declaration or definition (or in the catch clause of an exception handler);
  • an identifier between the parentheses immediately following the macro name in a macro definition; or a template-parameter.

This example demonstrates the difference between a parameter and an argument

void func(int n, char * pc); //n and pc are parameters
template <class T> class A {}; //T is a a parameter

int main()
{
 char c;
 char *p = &c;
 func(5, p); //5 and p are arguments
 A<long> a; //'long' is an argument
 A<char> another_a; //'char' is an argument
 return 0;
}
Categories: Technology
  1. bigboxstore4
    December 23, 2009 at 9:35 AM

    I have seen your post and this post is very useful for us.I have read your all concepts that seems useful for us.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: