Posted by odesk test answer
1.Question
Consider the following code:
#include
using namespace std;
int main()
{
cout << "The value of __LINE__ is " <<__LINE__;
return 0;
}
What will be the result when the above code is compiled and executed?
Ans: c. The code will compile and run without errors
2.Question
Base class members are made accessible to a derived class and inaccessible to rest of the program by _____.
Ans: protected access specifier
3.Question
Which of the following is not a standard STL header?
Ans: a.
4.Question
Which of the following are true about class and struct in C++:
Ans: In a class all members are private by default, whereas in struct all members are public by default
5.Question
Consider the following code:
#include
using namespace std;
class A
{
public :
A()
{
cout << "Constructor of A\n";
};
~A()
{
cout << "Destructor of A\n";
};
};
class B : public A
{
public :
B()
{
cout << "Constructor of B\n";
};
~B()
{
cout << "Destructor of B\n";
};
};
int main()
{
B *pB;
pB = new B();
delete pB;
return 0;
}
What will be the printed output?
Ans: Constructor of A Constructor of B Destructor of B Destructor of A
6.Question
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:
Ans: 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;
7.Question
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)
{
}
};
Ans: a. Yes, it is valid
8.Question
Which of the following STL classes is deprecated (ie should no longer be used)
ostrstream
ostringstream
ostream
wostream
Ans: ostrstream
9.Question
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
Ans: 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
10.Question
Consider the following code:
class BaseException
{
public:
virtual void Output()
{
cout << "Base Exception" << endl;
}
};
class DerivedException : public BaseException
{
public:
virtual void Output()
{
cout << "Derived Exception" << endl;
}
};
void ExceptionTest()
{
try
{
throw new DerivedException();
}
catch (DerivedException ex)
{
ex.Output();
}
catch (...)
{
cout << "Unknown Exception Thrown!" << endl;
}
}
Invoking Exception Test will result in which output?
Ans: c. Unknown Exception Thrown
11.Question
What will be the output of the following code? Posted by odesk test answer
class b
{
int i;
public:
virtual void vfoo()
{
cout <<"Base ";
}
};
class d1 : public b
{
int j;
public:
void vfoo()
{
j++;
cout <<"Derived";
}
};
class d2 : public d1
{
int k;
};
void main()
{
b *p, ob;
d2 ob2;
p = &ob;
p->vfoo();
p = &ob2;
p->vfoo();
}
Ans: b. Base Derived
12.Question
What will be the output of the following code?
class A
{
public:
A():pData(0){}
~A(){}
int operator ++()
{
pData++;
cout << "In first ";
return pData;
}
int operator ++(int)
{
pData++;
cout << "In second ";
return pData;
}
private:
int pData;
};
void main()
{
A a;
cout << a++;
cout << ++a;
}
Ans: b. In second 1 In first 2
13.Question
Consider the following class hierarchy:
class Base
{
}
class Derived : private Base
{
}
Which of the following are true?
Ans: d. Derived can access public and protected member functions of Base
14.Question
Consider the sample code given below and answer the question that follows.
class A
{
public:
A() {}
~A()
{
cout << "in destructor" << endl;
}
};
void main()
{
A a;
a.~A();
}
How many times will "in destructor" be output when the above code is compiled and executed?
Ans: d. A compile time error will be generated because destructors cannot be called directly
15.Question
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?
Ans: e. The code will compile without errors
16.Question
A pure virtual function can be declared by _______.
Ans: b. equating it to 0
17.Question
Consider the sample code given below and answer the question that follows:
char **foo;
/* Missing code goes here */
for(int i = 0; i < 200; i++)
{
foo[i] = new char[100];
}
Referring to the sample code above, what is the missing line of code?
Ans: d. foo = new char*[200];
18.Question
Consider the following code:
class BaseException
{
public:
virtual void Output()
{ cout << "Base Exception" << endl; }
};
class DerivedException : public BaseException
{
public:
virtual void Output() { cout << "Derived Exception" << endl; }
};
void ExceptionTest()
{
try
{
throw DerivedException();
}
catch (BaseException& ex)
{
ex.Output();
}
catch (...)
{
cout << "Unknown Exception Thrown!" << endl;
}
}
Invoking Exception Test will result in which output?
Ans: b. Derived Exception
19.Question
Which of the following is a function that returns a non zero value to indicate an I/O stream error?
Ans: h. None of the above
20.Question
Consider the sample code given below and answer the question that follows.
class Shape
{
public:
virtual void draw() = 0;
};
class Rectangle: public Shape
{
public:
void draw()
{
// Code to draw rectangle
}
//Some more member functions.....
};
class Circle : public Shape
{
public:
void draw()
{
// Code to draw circle
}
//Some more member functions.....
};
int main()
{
Shape objShape;
objShape.draw();
}
What happens if the above program is compiled and executed?
Ans: e. None of the above
21.Question
What will be the output of the following code?
#include
using namespace std;
class b
{
int i;
public:
void vfoo()
{ cout <<"In Base "; }
};
class d : public b
{
int j;
public:
void vfoo()
{
cout<<"In Derived ";
}
};
void main()
{
b *p, ob;
d ob2;
p = &ob;
p->vfoo();
p = &ob2;
p->vfoo();
ob2.vfoo();
}
Ans: In Base In Base In Derived
22.Question
Which of the following statements about constructors and destructors are true?
Ans: c. Constructors can take parameters, but destructors cannot
e. It is illegal to define a constructor as virtual
23.Question
Consider the following class hierarchy:
class Base
{
}
class Derived : public Base
{
}
Which of the following are true?
Ans: d. Derived can access public and protected member functions of Base
e. The following line of code is valid: Base *object = new Derived();
24.Question
Consider the sample code given below and answer the question that follows.
template Run;
Which one of the following is an example of the sample code given above?
Ans: c. A template function declaration
25.Question
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 { };
Referring to the sample code above, which of the following data members of X are accessible from class Y
Ans: a. c
b. f
26.Question
Consider the following statements relating to static member functions and choose the appropriate options:
1. They have external linkage
2. They do not have 'this' pointers
3. They can be declared as virtual
4. They can have the same name as a non-static function that has the same argument types
Ans: c. Only 1 and 2 are true
27.Question
Which of the following operators cannot be overloaded?
a. +=
b. >>
c. <
d. .
e. ::
f. &&
g. =
h. ?:
Ans: d. .
e. ::
h. ?:
28.Question
Consider the sample code given below and answer the question that follows.
class Person
{
string name;
int age;
Person *spouse;
public:
Person(string sName);
Person(string sName, int nAge);
Person(const Person& p);
Copy(Person *p);
Copy(const Person &p);
SetSpouse(Person *s);
};
Which one of the following are declarations for a copy constructor?
Ans: d. Person(const Person &p);
29.Question
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
Ans: e. All of the above
30.Question
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
posted by khalequzzaman
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
Ans: d. You can create arrays of functions
31.Question
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
Ans: b. Throw an exception from the constructor
32.Question
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
Ans: b. protected
33.Question
Consider the following code:
#include
int main(int argc, char* argv[])
{
enum Colors
{
red,
blue,
white = 5,
yellow,
green,
pink
};
Colors color = green;
printf("%d", color);
return 0;
}
What will be the output when the above code is compiled and executed?
Ans: d. 7
34.Question
Which of the following are NOT valid C++ casts
a. dynamic_cast
b. reinterpret_cast
c. static_cast
d. const_cast
e. void_cast
Ans: e. void_cast
35.Question
Consider the following code:
class BaseException
{
public:
virtual void Output()
{
cout << "Base Exception" << endl;
}
};
class DerivedException : public BaseException
{
public:
virtual void Output()
{
cout << "Derived Exception" << endl;
}
};
void ExceptionTest()
{
try
{
throw DerivedException();
}
catch (BaseException ex)
{
ex.Output();
}
catch (...)
{
cout << "Unknown Exception Thrown!" << endl;
}
}
posted by khalequzzaman
Invoking Exception Test will result in which output?
Ans: a. Base Exception
36.Question
Which of the following is NOT a standard sorting algorithm:
a. std::sort
b. std::qsort
c. std::stable_sort
d. std::partial_sort
Ans: b. std::qsort
37.Question
How many arguments can be passed to an overloaded binary operator?
a. 4
b. 3
c. 2
d. 1
e. 0
Ans: d. 1
38.Question
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
Ans: d. std::cerr
39.Question
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
Ans: 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
40.Question
Consider the sample code given below and answer the question that follows.
class Outer
{
public:
class Inner
{
int Count;
public:
Inner(){};
};
};
int main()
{
Inner innerObject;
Outer outObject;
return 0;
}
What will be the result when the above code is compiled?
Ans: d. There will be an error because in the declaration of innerObject the type Inner must be qualified by Outer
41.Question
Consider the sample code given below and answer the question that follows.
1 class Car
2 {
3 private:
4 int Wheels;
5
6 public:
7 Car(int wheels = 0)
8 : Wheels(wheels)
9 {
10 }
11
12 int GetWheels()
13 {
14 return Wheels;
15 }
16 };
17 main()
18 {
19 Car c(4);
20 cout << "No of wheels:" << c.GetWheels();
21 }
Which of the following lines from the sample code above are examples of data member definition?
Which of the following lines from the sample code above are examples of data member definition?
Ans: e. 19
42.Question
What is the output of the following code segment?
int n = 9;
int *p;
p=&n;
n++;
cout << *p+2 << "," << n;
Ans: c. 12,10
43.Question
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
Ans: a. A derived class can call the destructor of the parent class explicitly
44.Question
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
Ans: c. terminate
45.Question
Sample Code
typedef char *monthTable[3];
Referring to the code above, which of the following choices creates two monthTable arrays and initializes one of the two?
Ans: e. monthTable winter,spring={"March","April","May"};
46.QuestionWhat happened when the following code is compiled and executed?
#include
using namespace std;
class myclass
{
private:
int number;
public:
myclass()
{
number = 2;
}
int &a()
{
return number;
}
};
int main()
{
myclass m1,m2;
m1.a() = 5;
m2.a() = m1.a();
cout<
return 0;
}
Ans: b. The printed output will be 5
47.Question
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
Ans: a. add
48.Question
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
Ans: c. Write the error to a log file
49.Question
Which of the following are NOT valid C++ casts
a. dynamic_cast
b. reinterpret_cast
c. static_cast
d. const_cast
e. void_cast
Ans: e. void_cast
50.Question
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
Ans: c. Declaration of a local variable
51.Question
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
Ans: 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
52.Question
State whether True or False.
Unary operator, overloaded by means of a friend function take one reference argument.
Ans: a. True
53.Question
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
Ans: a. fstream
Consider the following code:
#include
using namespace std;
int main()
{
cout << "The value of __LINE__ is " <<__LINE__;
return 0;
}
What will be the result when the above code is compiled and executed?
Ans: c. The code will compile and run without errors
2.Question
Base class members are made accessible to a derived class and inaccessible to rest of the program by _____.
Ans: protected access specifier
3.Question
Which of the following is not a standard STL header?
Ans: a.
4.Question
Which of the following are true about class and struct in C++:
Ans: In a class all members are private by default, whereas in struct all members are public by default
5.Question
Consider the following code:
#include
using namespace std;
class A
{
public :
A()
{
cout << "Constructor of A\n";
};
~A()
{
cout << "Destructor of A\n";
};
};
class B : public A
{
public :
B()
{
cout << "Constructor of B\n";
};
~B()
{
cout << "Destructor of B\n";
};
};
int main()
{
B *pB;
pB = new B();
delete pB;
return 0;
}
What will be the printed output?
Ans: Constructor of A Constructor of B Destructor of B Destructor of A
6.Question
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:
Ans: 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;
7.Question
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)
{
}
};
Ans: a. Yes, it is valid
8.Question
Which of the following STL classes is deprecated (ie should no longer be used)
ostrstream
ostringstream
ostream
wostream
Ans: ostrstream
9.Question
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
Ans: 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
10.Question
Consider the following code:
class BaseException
{
public:
virtual void Output()
{
cout << "Base Exception" << endl;
}
};
class DerivedException : public BaseException
{
public:
virtual void Output()
{
cout << "Derived Exception" << endl;
}
};
void ExceptionTest()
{
try
{
throw new DerivedException();
}
catch (DerivedException ex)
{
ex.Output();
}
catch (...)
{
cout << "Unknown Exception Thrown!" << endl;
}
}
Invoking Exception Test will result in which output?
Ans: c. Unknown Exception Thrown
11.Question
What will be the output of the following code? Posted by odesk test answer
class b
{
int i;
public:
virtual void vfoo()
{
cout <<"Base ";
}
};
class d1 : public b
{
int j;
public:
void vfoo()
{
j++;
cout <<"Derived";
}
};
class d2 : public d1
{
int k;
};
void main()
{
b *p, ob;
d2 ob2;
p = &ob;
p->vfoo();
p = &ob2;
p->vfoo();
}
Ans: b. Base Derived
12.Question
What will be the output of the following code?
class A
{
public:
A():pData(0){}
~A(){}
int operator ++()
{
pData++;
cout << "In first ";
return pData;
}
int operator ++(int)
{
pData++;
cout << "In second ";
return pData;
}
private:
int pData;
};
void main()
{
A a;
cout << a++;
cout << ++a;
}
Ans: b. In second 1 In first 2
13.Question
Consider the following class hierarchy:
class Base
{
}
class Derived : private Base
{
}
Which of the following are true?
Ans: d. Derived can access public and protected member functions of Base
14.Question
Consider the sample code given below and answer the question that follows.
class A
{
public:
A() {}
~A()
{
cout << "in destructor" << endl;
}
};
void main()
{
A a;
a.~A();
}
How many times will "in destructor" be output when the above code is compiled and executed?
Ans: d. A compile time error will be generated because destructors cannot be called directly
15.Question
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?
Ans: e. The code will compile without errors
16.Question
A pure virtual function can be declared by _______.
Ans: b. equating it to 0
17.Question
Consider the sample code given below and answer the question that follows:
char **foo;
/* Missing code goes here */
for(int i = 0; i < 200; i++)
{
foo[i] = new char[100];
}
Referring to the sample code above, what is the missing line of code?
Ans: d. foo = new char*[200];
18.Question
Consider the following code:
class BaseException
{
public:
virtual void Output()
{ cout << "Base Exception" << endl; }
};
class DerivedException : public BaseException
{
public:
virtual void Output() { cout << "Derived Exception" << endl; }
};
void ExceptionTest()
{
try
{
throw DerivedException();
}
catch (BaseException& ex)
{
ex.Output();
}
catch (...)
{
cout << "Unknown Exception Thrown!" << endl;
}
}
Invoking Exception Test will result in which output?
Ans: b. Derived Exception
19.Question
Which of the following is a function that returns a non zero value to indicate an I/O stream error?
Ans: h. None of the above
20.Question
Consider the sample code given below and answer the question that follows.
class Shape
{
public:
virtual void draw() = 0;
};
class Rectangle: public Shape
{
public:
void draw()
{
// Code to draw rectangle
}
//Some more member functions.....
};
class Circle : public Shape
{
public:
void draw()
{
// Code to draw circle
}
//Some more member functions.....
};
int main()
{
Shape objShape;
objShape.draw();
}
What happens if the above program is compiled and executed?
Ans: e. None of the above
21.Question
What will be the output of the following code?
#include
using namespace std;
class b
{
int i;
public:
void vfoo()
{ cout <<"In Base "; }
};
class d : public b
{
int j;
public:
void vfoo()
{
cout<<"In Derived ";
}
};
void main()
{
b *p, ob;
d ob2;
p = &ob;
p->vfoo();
p = &ob2;
p->vfoo();
ob2.vfoo();
}
Ans: In Base In Base In Derived
22.Question
Which of the following statements about constructors and destructors are true?
Ans: c. Constructors can take parameters, but destructors cannot
e. It is illegal to define a constructor as virtual
23.Question
Consider the following class hierarchy:
class Base
{
}
class Derived : public Base
{
}
Which of the following are true?
Ans: d. Derived can access public and protected member functions of Base
e. The following line of code is valid: Base *object = new Derived();
24.Question
Consider the sample code given below and answer the question that follows.
template Run;
Which one of the following is an example of the sample code given above?
Ans: c. A template function declaration
25.Question
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 { };
Referring to the sample code above, which of the following data members of X are accessible from class Y
Ans: a. c
b. f
26.Question
Consider the following statements relating to static member functions and choose the appropriate options:
1. They have external linkage
2. They do not have 'this' pointers
3. They can be declared as virtual
4. They can have the same name as a non-static function that has the same argument types
Ans: c. Only 1 and 2 are true
27.Question
Which of the following operators cannot be overloaded?
a. +=
b. >>
c. <
d. .
e. ::
f. &&
g. =
h. ?:
Ans: d. .
e. ::
h. ?:
28.Question
Consider the sample code given below and answer the question that follows.
class Person
{
string name;
int age;
Person *spouse;
public:
Person(string sName);
Person(string sName, int nAge);
Person(const Person& p);
Copy(Person *p);
Copy(const Person &p);
SetSpouse(Person *s);
};
Which one of the following are declarations for a copy constructor?
Ans: d. Person(const Person &p);
29.Question
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
Ans: e. All of the above
30.Question
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
posted by khalequzzaman
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
Ans: d. You can create arrays of functions
31.Question
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
Ans: b. Throw an exception from the constructor
32.Question
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
Ans: b. protected
33.Question
Consider the following code:
#include
int main(int argc, char* argv[])
{
enum Colors
{
red,
blue,
white = 5,
yellow,
green,
pink
};
Colors color = green;
printf("%d", color);
return 0;
}
What will be the output when the above code is compiled and executed?
Ans: d. 7
34.Question
Which of the following are NOT valid C++ casts
a. dynamic_cast
b. reinterpret_cast
c. static_cast
d. const_cast
e. void_cast
Ans: e. void_cast
35.Question
Consider the following code:
class BaseException
{
public:
virtual void Output()
{
cout << "Base Exception" << endl;
}
};
class DerivedException : public BaseException
{
public:
virtual void Output()
{
cout << "Derived Exception" << endl;
}
};
void ExceptionTest()
{
try
{
throw DerivedException();
}
catch (BaseException ex)
{
ex.Output();
}
catch (...)
{
cout << "Unknown Exception Thrown!" << endl;
}
}
posted by khalequzzaman
Invoking Exception Test will result in which output?
Ans: a. Base Exception
36.Question
Which of the following is NOT a standard sorting algorithm:
a. std::sort
b. std::qsort
c. std::stable_sort
d. std::partial_sort
Ans: b. std::qsort
37.Question
How many arguments can be passed to an overloaded binary operator?
a. 4
b. 3
c. 2
d. 1
e. 0
Ans: d. 1
38.Question
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
Ans: d. std::cerr
39.Question
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
Ans: 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
40.Question
Consider the sample code given below and answer the question that follows.
class Outer
{
public:
class Inner
{
int Count;
public:
Inner(){};
};
};
int main()
{
Inner innerObject;
Outer outObject;
return 0;
}
What will be the result when the above code is compiled?
Ans: d. There will be an error because in the declaration of innerObject the type Inner must be qualified by Outer
41.Question
Consider the sample code given below and answer the question that follows.
1 class Car
2 {
3 private:
4 int Wheels;
5
6 public:
7 Car(int wheels = 0)
8 : Wheels(wheels)
9 {
10 }
11
12 int GetWheels()
13 {
14 return Wheels;
15 }
16 };
17 main()
18 {
19 Car c(4);
20 cout << "No of wheels:" << c.GetWheels();
21 }
Which of the following lines from the sample code above are examples of data member definition?
Which of the following lines from the sample code above are examples of data member definition?
Ans: e. 19
42.Question
What is the output of the following code segment?
int n = 9;
int *p;
p=&n;
n++;
cout << *p+2 << "," << n;
Ans: c. 12,10
43.Question
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
Ans: a. A derived class can call the destructor of the parent class explicitly
44.Question
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
Ans: c. terminate
45.Question
Sample Code
typedef char *monthTable[3];
Referring to the code above, which of the following choices creates two monthTable arrays and initializes one of the two?
Ans: e. monthTable winter,spring={"March","April","May"};
46.QuestionWhat happened when the following code is compiled and executed?
#include
using namespace std;
class myclass
{
private:
int number;
public:
myclass()
{
number = 2;
}
int &a()
{
return number;
}
};
int main()
{
myclass m1,m2;
m1.a() = 5;
m2.a() = m1.a();
cout<
return 0;
}
Ans: b. The printed output will be 5
47.Question
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
Ans: a. add
48.Question
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
Ans: c. Write the error to a log file
49.Question
Which of the following are NOT valid C++ casts
a. dynamic_cast
b. reinterpret_cast
c. static_cast
d. const_cast
e. void_cast
Ans: e. void_cast
50.Question
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
Ans: c. Declaration of a local variable
51.Question
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
Ans: 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
52.Question
State whether True or False.
Unary operator, overloaded by means of a friend function take one reference argument.
Ans: a. True
53.Question
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
Ans: a. fstream
Posted by odesk test answer
No comments:
Post a Comment