void Aint m int n main int a0 b0 A print ab Problem 6

void A(int m, int n) {

}
main () {

int a=0, b=0; A( , );
print a,b;

}

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, value return. Expla each parameter passing mode based on your solution. void A (int m, int n) i by reference, or by in what will be printed out for main () int a-0, b-0; print a,b;

Solution

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

//If the parameters are passed by value: No modification done in the function A() will be replicated in main()
//And therefore, the output in main() will print the same old values 0, and 0.

//If the parameters are passed by reference: The modifications done in the function A() will be replicated in main()
//And therefore, the output in main() will now print the new values 1, and 1.

//As this is a void returning function, the function will not return anything.
//If we change the return type also, assume like this:
int A(int m, int n)
{
return m + n + 10;
}
main()
{
int a = 0, b = 0;
a = A(a, b);
print a, b;
}
//Now, the values to be printed in main() will be 10, 0.

void A(int m, int n) { } main () { int a=0, b=0; A( , ); print a,b; } Problem 6 [10pt] Insert one or two statements in function A and insert arguments into the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site