Return to parameter passing

Examples of Parameter Passing:

Pass-By-Value-Result:
All possible situations depend on language implementation.
void swap(int a, int b)
{
  int temp = a;
  a = b;
  b = temp;
}

void main()
{
 int i=3;
 int list[5]={ 2, 0, 4, 1, 3};
 swap(i, list[i]);
}

1. The time to bind b and list[i] can be
   a. At the time calling subprogram.
      b will bind to list[3] in the above example.
   b. At the time returning to main program.
      b will copy back to list[1] in the above example.

2. Pass back from left to right or from right to left.
   a. from left to right:
      b will copy back to list[1] in the above example.
   b. from right to left:
      b will bind to list[3] in the above example.

Pass-By-Name:

int global = 3;

void fun(int a, int b)
{
 global = global + 1;
 a = a + 12;  ---------> global = global + 12;
 b = b - 2;   ---------> x = x - 2;
 cout<<"a = " << a <<endl;
 cout<<"b = " << b <<endl;
 cout<<"global = " << global <<endl;
}
main()
{
 int x = 5;
 fun(global, x);
 x = x + 3;
 cout<<"After call \n";
 cout<<"global = " << global <<endl;
 cout<<"x = " << x <<endl;
}
¡@