C++ Misc

Last Updated :
Discuss
Comments

Question 1

A member function can always access the data in __________ , (in C++).
  • the class of which it is member
  • the object of which it is a member
  • the public part of its class
  • the private part of its class

Question 2

Which of the following is not correct for virtual function in C++ ?

  • Must be declared in public section of class.

  • Virtual function can be static.

  • Virtual function should be accessed using pointers.

  • Virtual function is defined in base class.

Question 3

Which of the following is not correct (in C++) ?

  1. Class templates and function templates are instantiated in the same way
  2. Class templates differ from function templates in the way they are initiated
  3. Class template is initiated by defining an object using the template argument
  4. Class templates are generally used for storage classes
  • (1)

  • (2), (4)

  • (2), (3), (4)

  • (4)

Question 4

Inline functions are useful when
  • Function is large with many nested loops
  • Function has many static variables
  • Function is small and we want to avoid function call overhead.
  • None of the above

Question 5

C++
#include<iostream>
using namespace std;
int x = 1;
void fun()
{
    int x = 2;
    {
        int x = 3;
        cout << ::x << endl;
    }
}
int main()
{
    fun();
    return 0;
}
  • 1

  • 2

  • 3

  • 0

Question 6

How can we make a C++ class such that objects of it can only be created using new operator? If user tries to create an object directly, the program produces compiler error.
  • Not possible
  • By making destructor private
  • By making constructor private
  • By making both constructor and destructor private

Question 7

Would destructor be called, if yes, then due to which vector? C
#include <iostream>
#include <vector>
using namespace std;

class a
{
public :
    ~a()
    {
        cout << "destroy";
    }
};
int main()
{
   vector <a*> *v1  = new vector<a*>;
   vector <a> *v2  = new vector<a>;
   return 0;
}
  • v1
  • v2
  • v1 and v2
  • no destructor call

Question 8

C
#include<iostream>
using namespace std;

int x[100];
int main()
{
    cout << x[99] << endl;
}
This question is contributed by Sudheendra Baliga
  • Unpredictable
  • Runtime error
  • 0
  • 99

Question 9

In C++, polymorphism requires:
  • Inheritance only
  • Virtual functions only
  • References only
  • Inheritance, Virtual functions and references

Question 10

Method over-riding can be prevented by using final as a modifier at ______.
  • the start of the class.
  • the start of method declaration.
  • the start of derived class.
  • the start of the method declaration in the derived class.

There are 15 questions to complete.

Take a part in the ongoing discussion