Problem 6 10pt Insert one or two statements in function A an
Problem 6 [10pt] 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
The program showing passed by value, by reference is as follows:
#include <stdio.h>
void A(int *a, int *b);
void B(int a, int b);
int main()
{
int a = 0, b = 0;
printf(\" a = %d\ \", a);//a=0
printf(\" b = %d\ \", b); //b=0
// pass by value
B(a, b);
printf(\"After pass by value a = %d\ \", a);//a=0
printf(\"after pass by value b = %d\ \", b);//b=0
//pass by reference we pass the address of the variable
A(&a, &b);
printf(\"After reference a = %d\ \", a);//a=10
printf(\"after reference b = %d\ \", b);//b=20
return 0;
}
void A(int *a, int *b) {
*a = 10;
*b = 20;
}
void B(int a, int b) {
a = 10;
b = 20;
}
![Problem 6 [10pt] 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) w Problem 6 [10pt] 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) w](/WebImages/7/problem-6-10pt-insert-one-or-two-statements-in-function-a-an-992312-1761510370-0.webp)