C++ MCQ’s

C++ MCQ’s Home Page

C++ Basic 1
C++ Basic 2
C++ Basic 3
C++ Basic 4
C++ Basic 5
C++ OOPs Concepts 1
C++ OOPs Concepts 2
C++ OOPs Concepts 3
C++ OOPs Concepts 4
C++ OOPs Concepts 5

 

Cpp Language MCQ’S | OOPs Concepts Set 4

16.
Which of the following is correct about new and malloc?

a) Both are available in C
b) Pointer object initialization of a class with both new and malloc calls the constructor of that class
c) Pointer object initialization of a class using new involves constructor call whereas using malloc does not involve constructor call
d) Pointer object initialization of a class using malloc involves constructor call whereas using new does not involve constructor call

 

17.
What is virtual inheritance?

a) C++ technique to avoid multiple copies of the base class into children/derived class
b) C++ technique to avoid multiple inheritances of classes
c) C++ technique to enhance multiple inheritance
d) C++ technique to ensure that a private member of the base class can be accessed somehow

 

18.
What is the difference between delete and delete[] in C++?

a) delete is used to delete normal objects whereas delete[] is used to pointer objects
b) delete is a keyword whereas delete[] is an identifier
c) delete is used to delete single object whereas delete[] is used to multiple(array/pointer of) objects
d) delete is syntactically correct but delete[] is wrong and hence will give an error if used in any case

 

19.
What will be the output of the following C++ code?

#include <iostream>
using namespace std;
class A{
public:
A(){
cout<<“Constructor called\n”;
}
~A(){
cout<<“Destructor called\n”;
}
};
int main(int argc, char const *argv[])
{
A *a = new A[5];
delete a;
return 0;
}

a) “Constructor called” five times and then “Destructor called” five times
b) “Constructor called” five times and then “Destructor called” once
c) Error
d) Segmentation fault

 

20.
What will be the output of the following C++ code?

#include <iostream>
using namespace std;
class A{
public:
A(){
cout<<“Constructor called\n”;
}
~A(){
cout<<“Destructor called\n”;
}
};
int main(int argc, char const *argv[])
{
A *a = new A[5];
delete[] a;
return 0;
}

a) “Constructor called” five times and then “Destructor called” five times
b) “Constructor called” five times and then “Destructor called” once
c) Error
d) Segmentation fault

 

Visitor Counter

0056743