Given the following function definition
void calc (int a, int& b)
{
int c;
c = a + 2;
a = a * 3;
b = c + a;
}
What is the output of the following code fragment that invokes calc?
(All variables are of type int)
x = 1;
y = 2;
z = 3;
calc(x, y);
cout << x << " " << y << " " << z << endl;
A. 1 2 3
B. 1 6 3
C. 3 6 3
D. 1 14 9

Respuesta :

Answer:

The output of the given question is the option "B".

Explanation:

In the given code the output is the option B which is 1 6 3. Because in the function calc() we pass the two parameters and in this function we define an integer variable c that calculate the value of the variable a and b. in outside the function we declare three variable x,y and z in this we assign value that is 1,2,3 and call the function and print the value. The variable z is no pass in the function so the value of this variable is 3, x variable value is 1 and y variable value is 6. So the output of the code is 1 6 3.