Home / Engineering / CPP Programming MCQs / Page 2

CPP Programming MCQs | Page - 2

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.17K Points
Coach

Q. 11) Output of following C++ program?
#include<iostream>
using namespace std;
int main()
{
int x = 10;
int& ref = x;
ref = 20;
cout << "x = " << x << endl ;
x = 30;
cout << "ref = " << ref << endl;
return 0;
}

(A) x = 20; ref = 30
(B) x = 20; ref = 20
(C) x = 10; ref = 30
(D) x = 30; ref = 30
View Answer Discuss Share

M

Mr. Dubey • 51.17K Points
Coach

Q. 12) What is the difference between struct and class in C++?

(A) All members of a structure are public and structures don’t have constructors and destructors
(B) Members of a class are private by default and members of struct are public by default. When deriving a struct from a class/struct, default access-specifier for a base class/struct is public and when deriving a class, default access specifier is private.
(C) All members of a structure are public and structures don’t have virtual functions
(D) All of the above
View Answer Discuss Share

M

Mr. Dubey • 51.17K Points
Coach

Q. 13) Predict the output of following C++ program.
#include<iostream>
using namespace std;
class Empty {};
int main() {
cout << sizeof(Empty);
return 0;
}

(A) A non-zero value
(B) 0
(C) Compiler Error
(D) Runtime Error
View Answer Discuss Share

M

Mr. Dubey • 51.17K Points
Coach

Q. 14) class Test {
int x;
};
int main() {
Test t;
cout << t.x;
return 0;
}

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

M

Mr. Dubey • 51.17K Points
Coach

Q. 15) Which of the following is true?

(A) All objects of a class share all data members of class
(B) Objects of a class do not share non-static members. Every object has its own copy.
(C) Objects of a class do not share codes of non-static methods, they have their own copy
(D) None of the above
View Answer Discuss Share

M

Mr. Dubey • 51.17K Points
Coach

Q. 16) A member function can always access the data in __________, (in C++).

(A) the class of which it is member
(B) the object of which it is a member
(C) the public part of its class
(D) the private part of its class
View Answer Discuss Share

M

Mr. Dubey • 51.17K Points
Coach

Q. 17) Which of the following is not correct for virtual function in C++?

(A) Must be declared in public section of class.
(B) Virtual function can be static.
(C) Virtual function should be accessed using pointers.
(D) Virtual function is defined in base class.
View Answer Discuss Share

M

Mr. Dubey • 51.17K Points
Coach

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

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

M

Mr. Dubey • 51.17K Points
Coach

Q. 19) Which of the following cannot be passed to a function in C++?

(A) Constant
(B) Structure
(C) Array
(D) Header file
View Answer Discuss Share

M

Mr. Dubey • 51.17K Points
Coach

Q. 20) Which of the following, in C++, is inherited in a derived class from base class?

(A) Constructor
(B) Destructor
(C) Data members
(D) Virtual methods
View Answer Discuss Share