Insert one or two statements in function A and insert argume

Insert one or two statements in function A and insert arguments into the call to A such that the behavior of the program (values printed out) will differ depending upon whether parameters are passed by value, by reference, or by value return. Explain what will be printed out for each parameter passing mode based on your solution. void A(int m, int n) {} main () {int a=0, b=0; A (, ); print a, b;}

Solution

Answer:

Passed by value :

void A(int m,int n)
{
int read;
temp = m;
m= n;
n= read;
}
main()
{
   int a=0,b=0;
   A(a,b);
   print a,b;
}

In passed by value the values of a and b will not be interchanged and printed i.e the changes from the function are not reflected.

Passed by reference:

void A(int m,int n)
{

}
main()
{
   int a=0,b=0;
   A(&a,&b);
   print a,b;
}

In passed by reference the values of a and b will be interchanged and printed i.e the changes from the function are reflected.

 Insert one or two statements in function A and insert arguments into the call to A such that the behavior of the program (values printed out) will differ depen

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site