A pure virtual function can be declared by _______.
equating it to 1 0.0%
equating it to 0 87.0%
equating it to NULL 7.0%
the 'pure' keyword 0.0%
the 'abstract' keyword 5.0%
Base class members are made accessible to a derived class and inaccessible to rest of the program by _____.
public access specifier 0.0%
private access specifier 5.0%
protected access specifier 95.0%
friend access specifier 0.0%
Consider the following class hierarchy: class Base { } class Derived : private Base { } Which of the following are true?
The relation between Base and Derived can be described as: Base is a Derived 7.0%
The relation between Base and Derived can be described as: Base has a Derived 2.0%
Derived can access private member functions of Base 0.0%
Derived can access public and protected member functions of Base 89.0%
Consider the following class hierarchy: class Base { } class Derived : public Base { } Which of the following are true?
The relationship between the Base and Derived can be described as: Base is a Derived 0.0%
The relationship between the Base and Derived can be described as: Base has a Derived 2.0%
Derived can access only public member functions of Base 2.0%
Derived can access public and protected member functions of Base 46.0%
The following line of code is valid: Base *object = new Derived(); 48.0%
Consider the following code: class A { typedef int I; // private member I f(); friend I g(I); static I x; }; Which o...
A::I A::f() { return 0; } 42.0%
A::I g(A::I p = A::x); 11.0%
A::I g(A::I p) { return 0; } 31.0%
A::I A::x = 0; 14.0%
Consider the following code: #define SQ(a) (a*a) int answer = SQ(2 + 3); What will be the value of answer after the above code executes?
10 0.0%
11 75.0%
25 20.0%
13 4.0%
None of the above 0.0%
Consider the following code: #include<iostream> using namespace std; class A { public: A() { cout << "Constructor of A
"; }; ~A() { cout << "Destructor of A
"; }; }; class ...
Constructor of B Constructor of A Destructor of A Destructor of B 0.0%
Constructor of A Constructor of B Destructor of B Destructor of A 55.0%
Constructor of B Constructor of A Destructor of B Destructor of A 0.0%
Constructor of A Constructor of B Destructor of A Destructor of B 5.0%
The sequence of construction and destruction of A and B will be compiler specific 40.0%
Consider the following code: #include<iostream> using namespace std; int main() { cout << "The value of __LINE__ is " <<__LINE__; return 0; } What will be the result when the above code is comp...
The compilation will fail with the error - '__LINE__' : undeclared identifier 10.0%
The compilation will fail with the error - '__LINE__' unresolved identifier 0.0%
The code will compile and run without errors 89.0%
The code will crash at runtime 0.0%
Consider the following code: #include<stdio.h> int main(int argc, char* argv[]) { enum Colors { red, blue, white = 5, ...
4 0.0%
5 0.0%
6 0.0%
7 94.0%
8 0.0%
9 0.0%
The code will have compile time errors 5.0%
Consider the following code: class Animal { private: int weight; public: Animal() { } virtual void Speak() { cout << "Animal speaking"; } }; class Snake : pu...
The code will generate compilation errors 0.0%
The code will compile and run fine. "Animal speaking" will be printed to the output 4.0%
The code will compile and run fine. "Snake speaking" will be printed to the output 61.0%
The code will crash at runtime 33.0%
Consider the following code: class BaseException { public: virtual void Output() { cout << "Base Exception" << endl; } }; class DerivedException : public BaseException { publ...
Base Exception 0.0%
Derived Exception 0.0%
Unknown Exception Thrown 100.0%
No Output will be generated 0.0%
Consider the following code: class BaseException { public: virtual void Output() { cout << "Base Exception" << endl; } }; class DerivedException : public BaseException { public: ...
Base Exception 71.0%
Derived Exception 28.0%
Unknown Exception Thrown 0.0%
No Output will be generated 0.0%
Consider the following code: class BaseException { public: virtual void Output() { cout << "Base Exception" << endl; } }; class DerivedException : public BaseException { public: ...
Base Exception 0.0%
Derived Exception 100.0%
Unknown Exception Thrown 0.0%
No Output will be generated 0.0%
Consider the following code: template<class T> void Kill(T *& objPtr) { delete objPtr; objPtr = NULL; } class MyClass { }; void Test() { MyClass *ptr = new MyClass(); Kill(ptr); K...
Code will Crash or Throw and Exception 0.0%
Code will Execute, but there will be a memory leak 0.0%
Code will execute properly 84.0%
Code will exhibit undefined behavior 15.0%
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 ...
All are true 0.0%
Only 1, 2 and 4 are true 25.0%
Only 1 and 2 are true 68.0%
Only 1,3 and 4 are true 6.0%
All are false 0.0%
Consider the line of code given below and answer the question that follows. class screen; Which of the following statements are true about the class declaration above?
Incorrect syntax. The body of the class declaration is missing 0.0%
Incorrect syntax. {}; is missing 0.0%
The syntax is correct 100.0%
Incorrect syntax. {} is missing 0.0%
Incorrect syntax. Requires a * 0.0%
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 sampl...
foo = new *char[200]; 0.0%
foo = new char[200]; 0.0%
foo = new char[200]*; 0.0%
foo = new char*[200]; 100.0%
foo = new char[][200]; 0.0%
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 GetWheel...
4 100.0%
7 0.0%
8 0.0%
14 0.0%
19 0.0%
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 "...
0 0.0%
1 0.0%
2 100.0%
A compile time error will be generated because destructors cannot be called directly 0.0%
Consider the sample code given below and answer the question that follows. class Outer { public: class Inner { int Count; public: Inner(){}; }; }; int mai...
The code will compile fine 0.0%
There will be errors because classes cannot be defined inside other classes 0.0%
There will be an error because Outer does not define a constructor 0.0%
There will be an error because in the declaration of innerObject the type Inner must be qualified by Outer 100.0%
There will be no errors but a warning that Inner and Outer do not have destructors 0.0%
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 sNam...
Person(string sName); 0.0%
Person(string sName, int nAge); 0.0%
Copy(Person *p); 0.0%
Person(const Person &p); 100.0%
Copy(const Person &p)? 0.0%
Consider the sample code given below and answer the question that follows. class Person { public: Person(); virtual ~Person(); }; class Student : public Person { public: Student(); ...
To make it impossible for this particular destructor to be overloaded 0.0%
To ensure that correct destructor is called when p is deleted 38.0%
To ensure that the destructors are called in proper order 61.0%
To improve the speed of class Person's destruction 0.0%
To prevent the Person class from being instantiated directly making it an abstract base class 0.0%
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 ...
Object objShape of Shape class will be created 0.0%
A compile time error will be generated because you cannot declare Shape objects 100.0%
A compile time error will be generated because you cannot call draw function of class 'Shape' 0.0%
A compile time error will be generated because the derived class's draw() function cannot override the base class draw() function 0.0%
None of the above 0.0%
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 th...
SomeClass y(x); will generate an error because SomeClass has no copy constructor 0.0%
SomeClass y(x); will generate an error because SomeClass has no default constructor 6.0%
SomeClass y(x); will generate an error because SomeClass has no public copy constructor 6.0%
x(xx) will generate an error because it is illegal to initialize an int with that syntax 0.0%
The code will compile without errors 87.0%
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 c...
c 44.0%
f 44.0%
i 0.0%
None of the above 11.0%
Consider the sample code given below and answer the question that follows. template <class T> Run(T process); Which one of the following is an example of the sample code given above?
A non-template member function 0.0%
A template function definition 26.0%
A template function declaration 73.0%
A template class definition 0.0%
A template class declaration 0.0%
Consider two classes A and B: class A { private: int x; float y; public: friend class B; }; class B { }; Which of the following is true?
A can access all private data members of B 0.0%
B can access all private data members of A 72.0%
A cannot access the private members of B 27.0%
B cannot access the private members of A 0.0%
Both A and B can access each other's private data members 0.0%
How many arguments can be passed to an overloaded binary operator?
4 0.0%
3 0.0%
2 68.0%
1 32.0%
0 0.0%
If a matching catch handler (or ellipsis catch handler) cannot be found for the current exception, then the following predefined runtime function is called ______.
abort 0.0%
set_terminate 0.0%
terminate 100.0%
close 0.0%
If input and output operations have to be performed on a file, an object of the _______ class should be created.
fstream 88.0%
iostream 11.0%
ostream 0.0%
istream 0.0%
None 0.0%
In C++, the keyword auto can be used for:
Automatic assignment of data to objects during instantiation 0.0%
Automatic call of a function 0.0%
Declaration of a local variable 7.0%
Automatically erasing an object when it is no longer needed 0.0%
Automatic handling of run-time errors in the program 0.0%
Automatic termination of a program in case the user does not respond within a given time period 0.0%
Automatic creation of variables 92.0%
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) { } };
Yes, it is valid 100.0%
No, we cannot assign values like this 0.0%
No, the parenthesis cannot be empty 0.0%
No, var1 and var2 are not functions but are variables 0.0%
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?
monthTable(winter,spring={"March","April","May"}); 0.0%
monthTable winter, spring; 0.0%
monthTable, winter, spring; 0.0%
monthTable, winter,spring={"March","April","May"}; 0.0%
monthTable winter,spring={"March","April","May"}; 100.0%
State whether True or False. Unary operator overloaded by means of a friend function takes one reference argument.
State which of the following is true.
Function templates in C++ are used to create a set of functions that apply the same algorithm to different data types 100.0%
Classes in C++ are used to develop a set of type-safe classes 0.0%
C++ is useful for developing collection classes 0.0%
C++ is useful for developing smart pointers 0.0%
All of the above 0.0%
Suppose MyClass is a class that defines a copy constructor and overloads the assignment operator. In which of the following cases will the copy constructor of MyClass be called?
When an object of MyClass is passed by value to a function 21.0%
When an object of MyClass is returned by value from a function 21.0%
MyClass object1; MyClass object2; object2 = object1; 4.0%
MyClass object1; MyClass *object2 = new MyClass(object1); 30.0%
MyClass object1; MyClass object2 = object1; 21.0%
What access specifier allows only the class or a derived class to access a data member
private 0.0%
protected 85.0%
default 0.0%
virtual 0.0%
public 14.0%
What does ADT stand for?
Accessible derived type 0.0%
Access to derived type 0.0%
Abstract data type 100.0%
Abstract derived type 0.0%
Accessible data type 0.0%
What is the output of the following code segment? int n = 9; int *p; p=&n; n++; cout << *p+2 << "," << n;
11,9 0.0%
9,10 0.0%
12,10 100.0%
11,10 0.0%
What linkage specifier do you use in order to cause your C++ functions to have C linkage
extern "C" 100.0%
extern C 0.0%
_stdcall 0.0%
_cdecl 0.0%
_fastcall? 0.0%
What will be the output of the following code? #include<iostream> using namespace std; class b { int i; public: void vfoo() { cout <<"In Base "; } }; class d : public b { int j; public: void vfo...
In Base In Base In Derived 100.0%
In Base In Derived In Derived 0.0%
In Derived In Derived In Derived 0.0%
In Derived In Base In Derived 0.0%
In Base In Base In Base 0.0%
What will be the output of the following code? class A { public: A():pData(0){} ~A(){} int operator ++() { pData++; cout << "In first "; ...
In first 1 In second 2 0.0%
In second 1 In first 2 100.0%
In first 0 In second 2 0.0%
In second 0 In first 2 0.0%
What will be the output of the following code? class b { int i; public: virtual void vfoo() { cout <<"Base "; } }; class d1 : public b { int j; public: void vfoo() ...
Base Base 0.0%
Base Derived 100.0%
Derived Base 0.0%
Derived Derived 0.0%
What will happen when the following code is compiled and executed? #include<iostream> using namespace std; class myclass { private: int number; public: myclass() { number = 2;...
Compile time errors will be generated because right hand side of expressions cannot be functions 0.0%
The printed output will be 5 100.0%
The printed output will be 2 0.0%
The printed output will be undefined 0.0%
Which of the following are NOT valid C++ casts
dynamic_cast 0.0%
reinterpret_cast 0.0%
static_cast 0.0%
const_cast 0.0%
void_cast 100.0%
Which of the following are true about class and struct in C++:
A class can have destructor but a struct cannot 7.0%
A class can have inheritance but a struct cannot 0.0%
In a class all members are public by default, whereas in struct all members are private by default 0.0%
In a class all members are private by default, whereas in struct all members are public by default 92.0%
Which of the following are true about class member functions and constructors?
A constructor can return values but a member function cannot 0.0%
A member function can declare local variables but a constructor cannot 0.0%
A member function can return values but a constructor cannot 100.0%
A constructor can declare local variables but a member function cannot 0.0%
A member function can throw exceptions but a constructor cannot 0.0%
Which of the following is a function that returns a non zero value to indicate an I/O stream error?
bad 50.0%
good 6.0%
fail 18.0%
eof 12.0%
err 0.0%
error 0.0%
filerror 0.0%
None of the above 12.0%
Which of the following is a predefined object in C++ and used to insert to the standard error output?
std::err 0.0%
std::error 0.0%
std::cerror 0.0%
std::cerr 100.0%
std::cin 0.0%
std::clog 0.0%
Which of the following is NOT a standard sorting algorithm:
std::sort 0.0%
std::qsort 100.0%
std::stable_sort 0.0%
std::partial_sort 0.0%
Which of the following is not a standard STL header?
<array> 93.0%
<deque> 0.0%
<queue> 6.0%
<list> 0.0%
Which of the following member functions can be used to add an element in an std::vector?
add 0.0%
front 0.0%
push 0.0%
push_back 100.0%
Which of the following operators cannot be overloaded?
+= 0.0%
>> 0.0%
< 0.0%
. 33.0%
:: 33.0%
&& 0.0%
= 0.0%
?: 33.0%
Which of the following sets of functions do not qualify as overloaded functions?
void fun(int, char *) void fun(char *,int) 0.0%
void x(int,char) int *x(int,char) 100.0%
int get(int) int get(int,int) 0.0%
void F(int *) void F(float *) 0.0%
All of the above are overloaded functions 0.0%
Which of the following statements about constructors and destructors are true?
In a given class, constructors are always required to be defined, but destructors are not 0.0%
Neither constructors nor destructors can take parameters 0.0%
Constructors can take parameters, but destructors cannot 50.0%
It is illegal to define a destructor as virtual 0.0%
It is illegal to define a constructor as virtual 50.0%
Both explicitly declared constructors and explicitly declared destructors are required in a class 0.0%
Which of the following statements about function overloading, is true?
C++ and namespaces should be used to replace occurrences of function overloading 0.0%
Overloaded functions may not be declared as "inline" 0.0%
Although the return types and parameter types of overloaded functions can be different, the actual number of parameters cannot change 0.0%
Function overloading is possible in both C and C++ 69.0%
The parameter lists and const keyword are used to distinguish functions of the same name declared in the same scope 30.0%
Which of the following statements are FALSE with regard to destructors
A derived class can call the destructor of the parent class explicitly 12.0%
A class may have only one destructor 20.0%
Destructors cannot be invoked directly 24.0%
The return type for a destructor is void 20.0%
Destructors cannot accept arguments 24.0%
Which of the following statements are true about C++ vector class?
vector::empty deletes all elements of the vector 2.0%
vector::erase can be used to delete a single element and a range of elements of the vector 31.0%
After calling, vector::erase causes some of the iterators referencing the vector to become invalid 28.0%
vector::count returns the number of elements in the vector 2.0%
vector::size returns the number of elements in the vector 34.0%
vector::capacity returns the number of elements in the vector 0.0%
Which of the following statements are true for operator overloading in C++?
The * operator can be overloaded to perform division 22.0%
The * operator can be overloaded to perform assignment 38.0%
** can be overloaded to perform "to the power of" 0.0%
Operators can be overloaded only in inside classes 3.0%
Operators can be overloaded globally 35.0%
Which of the following statements are true?
Inline functions should be preferred over macros because inline functions have better performance 0.0%
Macro usage should be avoided because they are error prone 20.0%
Normal functions should be preferred over macros because normal functions have better performance 0.0%
Macro usage should be avoided because macros do not perform type checking 41.0%
Inline functions should be preferred over macros because inline functions perform type checking 37.0%
Which of the following statements regarding functions are false?
Functions can be overloaded 0.0%
Functions can return the type void 7.0%
Inline functions are expanded during compile time to avoid invocation overhead 0.0%
You can create arrays of functions 92.0%
You can pass values to functions by reference arguments 0.0%
You can return values from functions by reference arguments 0.0%
A function can return a pointer 0.0%
Which of the following STL classes is deprecated (ie should no longer be used)
ostrstream 100.0%
ostringstream 0.0%
ostream 0.0%
wostream 0.0%
Which of the following techniques should you use to handle a constructor that fails?
Return an error code from the constructor 0.0%
Throw an exception from the constructor 80.0%
Write the error to a log file 20.0%
Use "delete this;" in the constructor 0.0%
None of the above 0.0%
Which of the following techniques should you use to handle a destructor that fails?
Return an error code from the destructor 0.0%
Throw an exception from the destructor 0.0%
Write the error to a log file 16.0%
Use "delete this;" in the destructor 0.0%
None of the above 83.0%
You want the data member of a class to be accessed only by itself and by the class derived from it. Which access specifier will you give to the data member?
Public 0.0%
Private 7.0%
Protected 92.0%
Friend 0.0%
Either Public or Friend 0.0%