oDesk C++ Test Question Answers 2013-2014

Q1.Which of the following STL classes is deprecated (ie should no longer be used)? a.ostrstream
b.ostringstream
c.ostream
d.wostream
Q2.What access specifier allows only the class or a derived class to access a data member?
a. private
b. protected
c. default
d. virtual
e. public
Q3.Consider the following code:
class A {
typedef int I; // private member
I f();
friend I g(I);
static I x;
};
Which of the following are valid:
a. A::I A::f() { return 0; }
b. A::I g(A::I p = A::x);
c. A::I g(A::I p) { return 0; }
d. A::I A::x = 0;
Q4.In the given sample Code, is the constructor definition valid?
class someclass
{
int var1, var2;
public:
someclass(int num1, int num2) : var1(num1), var2(num2)
{
}
};
a. Yes, it is valid
b.Not Valid
Q5.Which of the following statements are true about C++ vector class?
a. vector::empty deletes all elements of the vector
b. vector::erase can be used to delete a single element and a range of elements of the vector
c. After calling, vector::erase causes some of the iterators referencing the vector to become invalid
d. vector::count returns the number of elements in the vector
e. vector::size returns the number of elements in the vector
f. vector::capacity returns the number of elements in the vector
Q6.Which of the following operators cannot be overloaded?
a. +=
b. >>
c. <
d. . 
e. ::
f. &&
g. =
h. ?:
Q7.State which of the following is true.
a. Function templates in C++ are used to create a set of functions that apply the same algorithm to different data types
b. Classes in C++ are used to develop a set of type-safe classes
c. C++ is useful for developing collection classes
d. C++ is useful for developing smart pointers
e. All of the above
Q8.Which of the following are NOT valid C++ casts
a. dynamic_cast
b. reinterpret_cast
c. static_cast
d. const_cast
e. void_cast
Q9.Which of the following member functions can be used to add an element in an std::vector?
a. add
b. front
c. push
d. push_back
Q10.Which of the following is a predefined object in C++ and used to insert to the standard error output?
a. std::err
b. std::error
c. std::cerror
d. std::cerr
e. std::cin
f. std::clog
Q11.In C++, the keyword auto can be used for:
a. Automatic assignment of data to objects during instantiation
b. Automatic call of a function
c. Declaration of a local variable
d. Automatically erasing an object when it is no longer needed
e. Automatic handling of run-time errors in the program
f. Automatic termination of a program in case the user does not respond within a given time period
g. Automatic creation of variables
Q12.Which of the following statements regarding functions are false?
a. Functions can be overloaded
b. Functions can return the type void
c. Inline functions are expanded during compile time to avoid invocation overhead
d. You can create arrays of functions
e. You can pass values to functions by reference arguments
f. You can return values from functions by reference arguments
g. A function can return a pointer
Q13.Which of the following techniques should you use to handle a constructor that fails?
a. Return an error code from the constructor
b. Throw an exception from the constructor
c. Write the error to a log file
d. Use “delete this;” in the constructor
e. None of the above
Q14.Which of the following is NOT a standard sorting algorithm:
a. std::sort
b. std::qsort
c. std::stable_sort
d. std::partial_sort
Q15.How many arguments can be passed to an overloaded binary operator?
a. 4
b. 3
c. 2
d. 1
e. 0
Q16.Which of the following statements are true?
a. Inline functions should be preferred over macros because inline functions have better performance
b. Macro usage should be avoided because they are error prone
c. Normal functions should be preferred over macros because normal functions have better performance
d. Macro usage should be avoided because macros do no perform type checking
e. Inline functions should be preferred over macros because inline functions perform type checking
Q17.Which of the following statements are FALSE with regard to destructors
a. A derived class can call the destructor of the parent class explicitly
b. A class may have only one destructor
c. Destructors cannot be invoked directly
d. The return type for a destructor is void
e. Destructors cannot accept arguments
Q18.If a matching catch handler (or ellipsis catch handler) cannot be found for the current exception, then the following predefined runtime function is called ______.
a. abort
b. set_terminate
c. terminate
d. close
Q19.Which of the following techniques should you use to handle a destructor that fails?
a. Return an error code from the destructor
b. Throw an exception from the destructor
c. Write the error to a log file
d. Use “delete this;” in the destructor
e. None of the above
Q20.Which of the following are NOT valid C++ casts
a. dynamic_cast
b. reinterpret_cast
c. static_cast
d. const_cast
e. void_cast
Q21.Which of the following statements are true for operator overloading in C++?
a. The * operator can be overloaded to perform division
b. The * operator can be overloaded to perform assignment
c. ** can be overloaded to perform “to the power of”
d. Operators can be overloaded only in inside classes
e. Operators can be overloaded globally
Q22.State whether True or False.
Unary operator, overloaded by means of a friend function take one reference argument.
a. True
b.False
Q23.If input and output operations have to be performed on a file, an object of the _______ class should be created.
a. fstream
b. iostream
c. ostream
d. istream
e. None