Home / Engineering / CPP Programming MCQs / Page 5

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.

M

Mr. Dubey • 51.43K Points
Coach

Q. 41) In C++, const qualifier can be applied to
1) Member functions of a class
2) Function arguments
3) To a class data member which is declared as static
4) Reference variables

(A) Only 1, 2 and 3
(B) Only 1, 2 and 4
(C) All
(D) Only 1, 3 and 4
View Answer Discuss Share

M

Mr. Dubey • 51.43K Points
Coach

Q. 42) 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]

(A) int *arr = new int *[10];
(B) int **arr = new int *[10];
(C) int *arr = new int [10];
(D) Not Possible
View Answer Discuss Share

M

Mr. Dubey • 51.43K Points
Coach

Q. 43) 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.

(A) 1 and 3
(B) 2 and 3
(C) 1 and 2
(D) All 1, 2 and 3
View Answer Discuss Share

M

Mr. Dubey • 51.43K Points
Coach

Q. 44) Predict the output?
#include <iostream>
using namespace std;
class Test
{
int x;
Test()
{
x = 5;
} };
int main()
{
Test *t = new Test;
cout << t->x;
}

(A) Compiler Error
(B) 5
(C) Garbage Value
(D) 0
View Answer Discuss Share

M

Mr. Dubey • 51.43K Points
Coach

Q. 45) 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;
}

(A) Yes
(B) No
(C) none
(D) all
View Answer Discuss Share

M

Mr. Dubey • 51.43K Points
Coach

Q. 46) When the inheritance is private, the private methods in base class are __________ in the derived class (in C++).

(A) inaccessible
(B) accessible
(C) protected
(D) public
View Answer Discuss Share

M

Mr. Dubey • 51.43K Points
Coach

Q. 47) What happens when delete is used for a NULL pointer?
int *ptr = NULL;
delete ptr;

(A) Compiler Error
(B) Run-time Crash
(C) No Error
(D) None
View Answer Discuss Share

M

Mr. Dubey • 51.43K Points
Coach

Q. 48) Which of the following is true about virtual functions in C++?

(A) Virtual functions are functions that can be overridden in derived class with the same signature.
(B) Virtual functions enable run-time polymorphism in a inheritance hierarchy.
(C) If a function is ‘virtual’ in the base class, the most-derived class implementation of the function is called according to the actual type of the object referred to, regardless of the declared type of the pointer or reference. In non-virtual f
(D) All of the above
View Answer Discuss Share

M

Mr. Dubey • 51.43K Points
Coach

Q. 49) 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.

(A) Both 1 and 2
(B) Only 1
(C) Only 2
(D) Neither 1 nor 2
View Answer Discuss Share

M

Mr. Dubey • 51.43K Points
Coach

Q. 50) What is the size of wchar_t in C++?

(A) 2
(B) 4
(C) 2 or 4
(D) Based on the number of bits in the system
View Answer Discuss Share