Difference between parameteres and arguments

This is a discussion on Difference between parameteres and arguments within the C++ Programming forums, part of the General Programming Boards category; For example take a loot at this: Code: int myFunc(int x, int y); //prototype The first keyword int represents the ...

  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 06: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
    32,824
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,272
    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
    22,269
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21