Thread: Difference between parameteres and arguments

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    66

    Difference between parameters and arguments

    For example take a loot at this:
    Code:
    int myFunc(int x, int y);       //prototype
    The first keyword int represents the type of myFunc.Right ?
    The next word myFunc is the name of my user defiened function. Right ?
    The () indicates the list of parameters. Right ?
    The int x and int y are the parameters followed by their type and name, separated by commas. Right ?

    Which are the arguments ? I think that they are the actual values of these variables passed to myFunc. Take a look:

    Code:
    #include <iostream>
    int myFunc(int x, int y);
    int main()
    {
                using std::cout;
                int result;
               
                result = myFunc(2,3);    //Are 2,3 the arguments ????? or they are parameters too ?
                cout << "2 multiple 3 = " << result << std::endl;
                std::system("PAUSE");
                return 0 ;
    }
    
    int myFunc(int x, int y)
    {
                 return (x * y);
    }
    Last edited by BlackSlash12; 08-28-2007 at 05:17 AM.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I think parameters and arguments are often used as synonyms. To make a distinction you might distinguish between the names of the variables declared in the function prototype and the values that are passed into the function (and these variables).
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Your sense of parameters and arguments seems about right to me.

    I don't recall at the moment if the standards define more specific terms though.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Strictly, a "parameter" is the abstract concept, and "argument" is the actual value passed during invokation. In practice, people use the two words interchangeably.

    In compiler design, we often refer to "formal parameters" and "actual parameters" to make the distinction clear.

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Quote Originally Posted by brewbuck View Post
    Strictly, a "parameter" is the abstract concept, and "argument" is the actual value passed during invokation. In practice, people use the two words interchangeably.

    In compiler design, we often refer to "formal parameters" and "actual parameters" to make the distinction clear.
    My interpretation of formal parameters/actual parameters was between function prototypes and function definitions. ie,

    Code:
    void foo(int blah);  // 'blah' is a formal parameter
    
    int main()
    {
        foo( 5 );  // 5 is the argument
    }
    
    void foo(int bar)  // 'bar' is the actual parameter
    {
        std::cout << bar;
    }

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Bjarne Stroustrup's C++ Glossary defines the terms as:
    argument - a value passed to a function or a template. In the case of templates, an argument is often a type.

    parameter - a variable declared in a function or templates for representing an argument. Also called a formal argument. Similarly, for templates.
    My understanding is that "parameters", "formal parameters" and "formal arguments" mean the same thing, and "arguments", "actual parameters" and "actual arguments" mean the same thing.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed