Week 8 Answers
1) Consider the following program.
What will be the outputs in consecutive two runs if statement—I is replaced by (i) testlt(3.14); and (ii) testlt(0); respectively?
a) int and (ii) string
b) double and (ii) string
c) float and (ii) anything else
d) double and (ii) anything else
Answer: A
2) Consider the following code segment.
What will be the output?
a) internal exception
b) SQL exception
c) DB exception
d) default
Answer: B
3) Consider the following code segment.
What will be the output?
a) internal error
b) sql error
c) db error
d) default
Answer: A
4) Consider the following code segment.
What will be the output/error?
a) default
b) int
c) double
d) Compiler error, handler must be the last handler for its try block
Answer: D
5) Consider the following code segment.
Identify the appropriate option to fill in the blanks at LINE—I and LINE—2 such that the output becomes 22.44, program.
a) LINE-I: class Modifier LINE-2: class Modifier
b) LINE-I: template LINE-2: template
c) LINE-I: class Modifier LINE-2: class Modifier
d) LINE-I: class Modifier LINE-2: template
Answer: B
6) Consider the following code segment.
What will be the output/error?
a) 3
b) hello hello hello
c) Compiler error at LINE—I: non-type argument is not allowed
d) Compiler error at LINE-2: non-type argument must be constant
Answer: D
7) Consider the following function template.
From among the following options, which generate(s) compiler error?
a) print(10, ‘a’);
b) print(10, 30);
c) print(10.34, 30);
d) print((int)’a’30)
Answer: A,C
8) Consider the following class definition in C++.
What is the appropriate function pointer declaration that can point to the function sum belonging to the class Computation as fpm = &Computation::sum;
?
a) typedef int (Computation: : * fpm) (int, int);
b) int Computation: : fpm(int, int);
c)int (Computation: : fpm) (int, int);
d)int (Computation: : *fpm) (int, int);
Answer: A
9) Consider the following code segment.
Identify the appropriate option to fill in the blank at LINE—I such that the output becomes d = 11
.
a) int operator(int d1, int d2)
b) int operator() (int d1, int d2)
c) void operator() (int d1, int d2)
d) int operator(int d1, int d2) ( )
Answer: B