Question:

What is parameter passing? name three ways of passing parameter during subroutine call?

by  |  earlier

0 LIKES UnLike

computer architecture

 Tags:

   Report

4 ANSWERS


  1. A subroutine takes parameters, variables set when it's called.  The caller passes values for those parameters.  Depending on the language, you can either pass a value, or a pointer (aka reference) to that value.  Beats me what the 3rd way is, and I've programmed for 30 years.  Maybe your teacher wants to hear IN, OUT and IN/OUT, referring to the direction the value passes.


  2. A way of sending argument(s) to a routine.

    Pass by

    1. Reference - address of the argument is passed into the sub, so that its value may be changed.

    2. Value - A copy of the argument is passed into the sub, so the actual arg is not changed, only the copy.

    3. Result Value - Is a combo of pass by value and pass by Reference.

    The argument is passed by reference, the sub makes a temp copy of the argument. Then it uses the temp argument, and when the sub is done, it copies the tmp argument back into the original argument.

  3. Parameter passing methods  are the ways in which parameters are transfered between functions when one function calls another. C++ provides two parameter passing methods--pass-by-value  and pass-by-reference .

    1: pass by value,

    2: pass by reference

    for example:

    if u have toswap the value of two varaibles :- say i and j than : using first method:

    void main()

    {

      int  i  = 20 , j   = 10;

      swap(i, j)// passed by value

    }

    int swap(int x, int y)

    {

    .....................

    }

    II method............

    void main()

    {

    swap(&i, &j)// pass by reference.

    }

  4. direct, indirect, indexed

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions