204k views
1 vote
Given the following function definitions and program fragments, what is the output?

void f1 (int* z, int *q)
{
int temp
temp = *q;
*q = *z;
*z = temp;
}
void f2( int* a, int* b)
{
if(*a < *b)
f1(a,b);
else
*a = *b;
}

int x = 3, y = 4
f2(&y, &x);
print("%d %d\\", x, y);

A) 3 4
B) 4 3
C) 4 4
D) 3 3

User Cuppy
by
8.4k points

1 Answer

5 votes

Final answer:

The program will output the values 4 and 3.

Step-by-step explanation:

The program is given the function definitions for f1 and f2, and is asked to output the values of x and y after executing f2(&y, &x).

In the given code, f1 swaps the values of z and q, and f2 calls f1 if the value of a is less than the value of b. Otherwise, it assigns the value of b to a.

Since y is passed as the first argument to f2 and x is passed as the second argument, f2(&y, &x) will call f1(&y, &x). This means that the values of y and x will be swapped, resulting in the output of 4 3.

User Coren
by
7.8k points