• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C++ Misc

Question 1

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 2

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 3

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 4

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 5

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 6

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 7

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 8

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

Question 9

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.

Question 10

In C, what is the effect of a negative number in a field width specifier?
  • the values are displayed right justified
  • the values are displayed centered
  • the values are displayed left justified
  • the values are displayed as negative numbers

There are 15 questions to complete.

Last Updated :
Take a part in the ongoing discussion