A directory of Objective Type Questions covering all the Computer Science subjects. Here you can access and discuss Multiple choice questions and answers for various compitative exams and interviews.

91. In the following C program fragment, j, k n and TwoLog_n are interger variables, and A is an array of integers. The variable n is initialized to an integer ≥ 3, and TwoLog_n is initialized to the value of 2*⌈log2(n)⌉

for (k = 3; k < = n; k++)
A[k] = 0;
for (k = 2; k < = TwoLog_n; k++)
for (j = k + 1; j < = n; j++)
A[j] = A[j] || (j % k);
for (j = 3; j < = n; j++)
if (!A[j]) printf("%d", j);

The set of numbers printed by this program fragment is
a. {m | m ≤ n, (∃ i) [m = i!]} Here i! mean factorial of i
b. {m | m ≤ n, (∃ i) [m = i^2]}
c. {m | m ≤ n, m is prime}
d. {}
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).{m | m ≤ n, (∃ i) [m = i^2]}

92. Consider the C program shown below.

#define print(x) printf("%d ", x)
int x;
void Q(int z)
{
z += x;
print(z);
}
void P(int *y)
{
int x = *y + 2;
Q(x);
*y = x - 1;
print(x);
}
main(void)
{
x = 5;
P(&x);
print(x);
}

The output of this program is
a. 12 7 6
b. 22 12 11
c. 14 6 6
d. 7 6 6
View Answer Report Discuss Too Difficult! Search Google
Answer: (a).12 7 6

93. The goal of structured programming is to
a. have well indented programs
b. be able to infer the flow of control from the compiled code
c. be able to infer the flow of control from the program text
d. avoid the use of GOTO statements
View Answer Report Discuss Too Difficult! Search Google
Answer: (c).be able to infer the flow of control from the program text

94. Consider the following C function

void swap (int a, int b)
{
   int temp;
   temp = a;
   a = b;
   b = temp;
}

In order to exchange the values of two variables x and y.
a. Call swap (x, y)
b. Call swap (&x, &y)
c. swap(x,y) cannot be used as it does not return any value
d. swap(x,y) cannot be used as the parameters are passed by value
View Answer Report Discuss Too Difficult! Search Google
Answer: (d).swap(x,y) cannot be used as the parameters are passed by value

95. The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5, 15, 12, 16. What is the height of the binary search tree (the height is the maximum distance of a leaf node from the root)?
a. 2
b. 3
c. 4
d. 6
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).3

96. The best data structure to check whether an arithmetic expression has balanced parentheses is a
a. queue
b. stack
c. tree
d. list
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).stack

97. Consider the following C function:

int f(int n)
{
static int i = 1;
if (n >= 5)
return n;
n = n+i;
i++;
return f(n);
}

The value returned by f(1) is
a. 5
b. 6
c. 7
d. 8
View Answer Report Discuss Too Difficult! Search Google
Answer: (c).7

98. Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let n = D1D2…Dm

int n, rev;
rev = 0;
while (n > 0)
{
rev = rev*10 + n%10;
n = n/10;
}

The loop invariant condition at the end of the ith iteration is:
a. n = D1D2….Dm-i and rev = DmDm-1…Dm-i+1
b. n = Dm-i+1…Dm-1Dm and rev = Dm-1….D2D1
c. n != rev
d. n = D1D2….Dm and rev = DmDm-1…D2D1
View Answer Report Discuss Too Difficult! Search Google
Answer: (a).n = D1D2….Dm-i and rev = DmDm-1…Dm-i+1

99. Consider the following C program segment:

char p[20];
char *s = "string";
int length = strlen(s);
int i;
for (i = 0; i < length; i++)
p[i] = s[length — i];
printf("%s",p);

The output of the program is
a. gnirts
b. gnirt
c. string
d. no output is printed
View Answer Report Discuss Too Difficult! Search Google
Answer: (d).no output is printed

100. It is desired to design an object-oriented employee record system for a company. Each employee has a name, unique id and salary. Employees belong to different categories and their salary is determined by their category. The functions to get Name, getld and compute salary are required. Given the class hierarchy below, possible locations for these functions are:

i. getld is implemented in the superclass
ii. getld is implemented in the subclass
iii. getName is an abstract function in the superclass
iv. getName is implemented in the superclass
v. getName is implemented in the subclass
vi. getSalary is an abstract function in the superclass
vii. getSalary is implemented in the superclass
viii. getSalary is implemented in the subclass.

Choose the best design.
classes and subclass in OOPS
a. (i), (iv), (vi), (viii)
b. (i), (iv), (vii)
c. (i), (iii), (v), (vi), (viii)
d. (ii), (v), (viii)
View Answer Report Discuss Too Difficult! Search Google
Answer: (a).(i), (iv), (vi), (viii)

Page 10 of 12