What c output would the following code segments display show
What c++ output would the following code segments display? show output here:
b.) What output would the following code segment display? show output here:
Solution
Question a:
Answer:
-5
-8
Explanation:
When we cal this function mystery(num, 2) here num value is 5
in mystery() this function, num value will be assigned by quant and 2 value will be assigned by pr;
quant = quant - quant * pr means
quant = 5 - 5 * 2;
quant = 5 - 10;
quant = -5
When we call this function mystery(2,num) here num value is 5
in mystery() this function, num value will be assigned by pr and 2 value will be assigned by quant ;
quant = quant - quant * pr means
quant = 2 - 2 * 5;
quant = 2 - 10;
quant = -8
Question b:
Answer:
9
8
7
Explanation:
num value is 3
and for loop running from 6 to 4. Eveny time loop will decrese by 1.
for (int i = 6; i > 3; i--){
mystery2(i + num);
}
in this loop i value initialy 6 and addding with num value and passing that value mystery2() method
so at i = 6, i + num = 6 + 3 = 9 value will be passed to function and print 9.
at i = 5, i + num = 5 + 3 = 8 value will be passed to function and print 8.
so at i = 4, i + num = 4 + 3 = 7 value will be passed to function and print 7.

