#include
using namespace std;
int main()
{
cout << "The value of __LINE__ is " <<__line__;>
What will be the result when the above code is compiled and executed?
Correct answer is:
c. The code will compile and run without errors
Which of the following are true about class and struct in C++:
Correct answer is:
In a class all members are private by default, whereas in struct all members are public by default
What will be the printed output?
Correct answer is:
Constructor of A Constructor of B Destructor of B Destructor of A
class A {
typedef int I; // private member
I f();
friend I g(I);
static I x;
};
Which of the following are valid:
Correct answer is:
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;
In the given sample Code, is the constructor definition valid?
Which of the following STL classes is deprecated (ie should no longer be used)
Which of the following statements are true about C++ vector class?
Correct answer is:
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
e. vector::size returns the number of elements in the vector
class BaseException
{
public:
virtual void Output()
{
cout << "Base Exception" <<>
Consider the following class hierarchy:
class Base
{
}
class Derived : private Base
{
}
Which of the following are true?
Correct answer is:
d. Derived can access public and protected member functions of Base
Consider the sample code given below and answer the question that follows.
class A
{
public:
A() {}
~A()
{
cout << "in destructor" <<>
How many times will "in destructor" be output when the above code is compiled and executed?
Correct answer is:
d. A compile time error will be generated because destructors cannot be called directly
Consider the sample code given below and answer the question that follows.
class SomeClass
{
int x;
public:
SomeClass (int xx) : x(xx) {}
};
SomeClass x(10);
SomeClass y(x);
What is wrong with the sample code above?
Correct answer is:
e. The code will compile without errors
Consider the sample code given below and answer the question that follows:
char **foo;
/* Missing code goes here */
for(int i = 0; i <>
Referring to the sample code above, what is the missing line of code?
class BaseException
{
public:
virtual void Output()
{ cout << "Base Exception" <<>
Which of the following is a function that returns a non zero value to indicate an I/O stream error?
a. bad
b. good
c. fail
d. eof
e. err
f. error
g. filerror
h. None of the above
Consider the sample code given below and answer the question that follows.
Which of the following statements about constructors and destructors are true?
Correct answer is:
c. Constructors can take parameters, but destructors cannot
e. It is illegal to define a constructor as virtual
Consider the following class hierarchy:
class Base
{
}
class Derived : public Base
{
}
Which of the following are true?
Correct answer is:
d. Derived can access public and protected member functions of Base
e. The following line of code is valid: Base *object = new Derived();
Consider the sample code given below and answer the question that follows.
Which one of the following is an example of the sample code given above?
Consider the sample code given below and answer the question that follows.
class X {
int i;
protected:
float f;
public:
char c;
};
class Y : private X { };
Consider the sample code given below and answer the question that follows.
Which one of the following are declarations for a copy constructor?
Which of the following techniques should you use to handle a constructor that fails?
Correct answer is:
b. Throw an exception from the constructor
What access specifier allows only the class or a derived class to access a data member?
Which of the following are NOT valid C++ casts?
a. dynamic_cast
b. reinterpret_cast
c. static_cast
d. const_cast
e. void_cast
class BaseException
{
public:
virtual void Output()
{
cout << "Base Exception" <<>
Which of the following is NOT a standard sorting algorithm:
a. std::sort
b. std::qsort
c. std::stable_sort
d. std::partial_sort
Which of the following statements are true?
Correct answer is:
b. Macro usage should be avoided because they are error prone
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
Consider the sample code given below and answer the question that follows.
What will be the result when the above code is compiled?
Correct answer is:
d. There will be an error because in the declaration of innerObject the type Inner must be qualified by Outer
What is the output of the following code segment?
Which of the following statements are FALSE with regard to destructors?
Correct answer is:
a. A derived class can call the destructor of the parent class explicitly
Which of the following member functions can be used to add an element in an std::vector?
Which of the following are NOT valid C++ casts?
a. dynamic_cast
b. reinterpret_cast
c. static_cast
d. const_cast
e. void_cast
Which of the following statements are true for operator overloading in C++?
Correct answer is:
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
a. fstream
b. iostream
c. ostream
d. istream
e. None
a. fstream
0 commentaires:
Enregistrer un commentaire