Q.1 What is the output of following program?
using namespace std;
int max(int& x, int& y, int& z)
{
if (x > y && y > z) {
y++;
z++;
return x++;
} else {
if (y > x)
return y++;
else
return z++;
}
}
int main()
{
int A, B;
int a = 10, b = 13, c = 8;
A = max(a, b, c);
cout
Option a) 3 3 b) 2 0 c) garbage value d) 2 3
Answer : c
Explanation : In this program, in given array we did not assign any value so it will be pointing to any garbage value. Q.2 What is the output of following program?
Option a) Computer Science, Mathematics b) Mathematics c) wrong choice d) error
Answer : c
Explanation : In this program, m is a variable and it is not assigned any value which means – m is having any garbage value. So, it doesn’t match any case and by default it will be print “wrong choice”. Q.3 What is the output of following program?
Option a) 3 4 5 6 7 b) 4 5 6 7 8 c) 2 3 4 5 6 d) none of above
Answer : a
Explanation : In this loop, simply first assign the value of y and then increment so no change. Q.4 What is the output of following program?
Option a) 10 14 8 or 14 13 8 b) 10 13 8 or 11 14 9 c) 10 14 9 or 14 12 9 d) 11 12 8 or 13 14 8
Answer : c
Explanation : Here, max function is to return max value and at the time of first print, the value of b decrements and remaining two a and c are same and remain same during second call of function. Q.5 What is the output of following program?
Option a) 10 8 6 -5 -6 b) 10 8 -4 -5 c) 10 8 -5 -6 d) 8 6 -4 -5
Answer : b
Explanation : First loop is executed and prints 10, 8 and then condition gets false, so loop exits. Then second loop is executed and checks the condition and print -4, -5 after that the condition becomes false then it gets terminated.