Skip to main content
Engineering LibreTexts

10.3: Arguments vs Parameters

  • Page ID
    29091
  • Argument vs Parameter in C++

    Argument

    An argument is referred to the values that are passed within a function when the function is called. These values are generally the source of the function that require the arguments during the process of execution. These values are assigned to the variables in the definition of the function that is called. The type of the values passed in the function is the same as that of the variables defined in the function definition. These are also called Actual arguments .

    Example: Suppose a sum() function is needed to be called with two numbers to add. These two numbers are referred to as the arguments and are passed to the sum() when it called from somewhere else.

    // C++ code to illustrate Arguments 
    #include <iostream> 
    using namespace std; 
    
    // sum: Function defintion 
    int sum(int in1, int in2) 
    { 
        // returning the addition 
        return in1 + in2; 
    } 
    
    // main() code 
    int main() 
    { 
        int num1 = 10, num2 = 20, results; 
    
        // sum() is called with 
        // num1 & num2 as ARGUMENTS. 
        // ALSO NOTICE - the sum() funtion returns an integer value
        // and the variable results will now contain that value
        // because of the assignment statement
        results = sum(num1, num2); 
    
        // Displaying the result 
        cout << "The summation is " << res; 
        return 0; 
    } 
    

    Make sure you take notice of the assignment of the returned value: results = sum(num1, num2); - we will discuss this more in a few lessons

    The summation is 30
    

    Parameters

    The parameter is referred to as the variables that are defined during a function declaration or definition. These variables are used to receive the arguments that are passed during a function call. These parameters within the function prototype are used during the execution of the function for which it is defined. These are also called Formal arguments or Formal Parameters. These are also called Actual Parameters.

    // C++ code to illustrate Parameters 
    
    #include <iostream> 
    using namespace std; 
    
    // Function declaration 
    // the 2 ints are the parameters 
    int Mult(int, int);
    
    // Driver code 
    int main() 
    { 
        int num1 = 10, num2 = 20, results; 
    
        // Mult() is called with 
        // num1 & num2 as ARGUMENTS. 
        results = Mult(num1, num2); 
    
        // Displaying the result 
        cout << "The multiplication is " << results; 
        return 0; 
    } 
    
    // Mult: Function defintion 
    // numIn1 and numIn2 are the parameters 
    int Mult(int numIn1, int numIn2) 
    { 
        // returning the results of the multiplication 
        return numIn1 * numIn2; 
    } 
    

    Again - arguments are the values that are passed in the function call. See the 3 highlighted comments in the code above, including the function prototype declaration

    The multiplication is 200
    

    Difference between Argument and Parameter

    ARGUMENT PARAMETER
    When a function is called, the values that are passed during the call are called as arguments. The values which are defined at the time of the function prototype or definition of the function are called as parameters.
    These are used in function call statement to send value from the calling function to the receiving function. These are used in function header of the called function to receive the value from the arguments.
    During the time of call each argument is always assigned to the parameter in the function definition. Parameters are local variables which are assigned value of the arguments when the function is called.
    They are also called Actual Parameters They are also called Formal Parameters
    Example:
    int num = 20; 
    someFunc(num) 
    // num is an argument 
    

     

    Example:
    int someFunc(int rnum) 
    { 
        cout << "The value is " << rnum << endl; 
    } 
    // rnum is parameter 
    

    Go