CPP Programming MCQs | Page - 5
Dear candidates you will find MCQ questions of CPP Programming here. Learn these questions and prepare yourself for coming examinations and interviews. You can check the right answer of any question by clicking on any option or by clicking view answer button.
Q. In C++, const qualifier can be applied to
β
Correct Answer: (C)
All
Q. How to create a dynamic array of pointers (to integers) of size 10 using new in C++? Hint: We can create a non-dynamic array using int *arr[10]
β
Correct Answer: (B)
int **arr = new int *[10];
Q. Which of the following is true about new when compared with malloc:
1) new is an operator, malloc is a function
2) new calls constructor, malloc doesn’t
3) new returns appropriate pointer, malloc returns void * and pointer needs to typecast to appropriate type.
β
Correct Answer: (D)
All 1, 2 and 3
Q. Predict the output?
#include <iostream>
using namespace std;
class Test
{
int x;
Test()
{
x = 5;
} };
int main()
{
Test *t = new Test;
cout << t->x;
}
β
Correct Answer: (A)
Compiler Error
Q. Is it fine to call delete twice for a pointer?
#include<iostream>
using namespace std;
int main()
{
int *ptr = new int;
delete ptr;
delete ptr;
return 0;
}
β
Correct Answer: (B)
No
Q. When the inheritance is private, the private methods in base class are __________ in the derived class (in C++).
β
Correct Answer: (A)
inaccessible
Q. What happens when delete is used for a NULL pointer?
int *ptr = NULL;
delete ptr;
β
Correct Answer: (C)
No Error
Q. Which of the following is true about virtual functions in C++?
β
Correct Answer: (D)
All of the above
Q. Which of the following is true about pure virtual functions?
1) Their implementation is not provided in a class where they are declared.
2) If a class has a pure virtual function, then the class becomes abstract class and an
instance of this class cannot be created.
β
Correct Answer: (C)
Only 2
Q. What is the size of wchar_t in C++?
β
Correct Answer: (D)
Based on the number of bits in the system
Jump to