Programming with C++ Test
A pure virtual function can be declared by _______.
Base class members are made accessible to a derived class and inaccessible to rest of the program by _____.
Consider the following class hierarchy: class Base { } class Derived : private Base { } Which of the following are true?
Consider the following class hierarchy: class Base { } class Derived : public Base { } Which of the following are true?
Consider the following code: class A { typedef int I; // private member I f(); friend I g(I); static I x; }; Which o...
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?
Consider the following code: #include<iostream> using namespace std; class A { public: A() { cout << "Constructor of A "; }; ~A() { cout << "Destructor of A "; }; }; class ...
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...
Consider the following code: #include<stdio.h> int main(int argc, char* argv[]) { enum Colors { red, blue, white = 5, ...
Consider the following code: class Animal { private: int weight; public: Animal() { } virtual void Speak() { cout << "Animal speaking"; } }; class Snake : pu...
Consider the following code: class BaseException { public: virtual void Output() { cout << "Base Exception" << endl; } }; class DerivedException : public BaseException { publ...
Consider the following code: class BaseException { public: virtual void Output() { cout << "Base Exception" << endl; } }; class DerivedException : public BaseException { public: ...
Consider the following code: class BaseException { public: virtual void Output() { cout << "Base Exception" << endl; } }; class DerivedException : public BaseException { public: ...
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...
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 ...
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?
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...
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...
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 "...
Consider the sample code given below and answer the question that follows. class Outer { public: class Inner { int Count; public: Inner(){}; }; }; int mai...
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...
Consider the sample code given below and answer the question that follows. class Person { public: Person(); virtual ~Person(); }; class Student : public Person { public: Student(); ...
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 ...
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...
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...
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?
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?
How many arguments can be passed to an overloaded binary operator?
If a matching catch handler (or ellipsis catch handler) cannot be found for the current exception, then the following predefined runtime function is called ______.
If input and output operations have to be performed on a file, an object of the _______ class should be created.
In C++, the keyword auto can be used for:
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) { } };
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?
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.
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?
What access specifier allows only the class or a derived class to access a data member
What does ADT stand for?
What is the output of the following code segment? int n = 9; int *p; p=&n; n++; cout << *p+2 << "," << n;
What linkage specifier do you use in order to cause your C++ functions to have C linkage
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...
What will be the output of the following code? class A { public: A():pData(0){} ~A(){} int operator ++() { pData++; cout << "In first "; ...
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() ...
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;...
Which of the following are NOT valid C++ casts
Which of the following are true about class and struct in C++:
Which of the following are true about class member functions and constructors?
Which of the following is a function that returns a non zero value to indicate an I/O stream error?
Which of the following is a predefined object in C++ and used to insert to the standard error output?
Which of the following is NOT a standard sorting algorithm:
Which of the following is not a standard STL header?
Which of the following member functions can be used to add an element in an std::vector?
Which of the following operators cannot be overloaded?
Which of the following sets of functions do not qualify as overloaded functions?
Which of the following statements about constructors and destructors are true?
Which of the following statements about function overloading, is true?
Which of the following statements are FALSE with regard to destructors
Which of the following statements are true about C++ vector class?
Which of the following statements are true for operator overloading in C++?
Which of the following statements are true?
Which of the following statements regarding functions are false?
Which of the following STL classes is deprecated (ie should no longer be used)
Which of the following techniques should you use to handle a constructor that fails?
Which of the following techniques should you use to handle a destructor that fails?
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?