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.
Q. Output of following C++ program?
β
Correct Answer: (A)
x = 20; ref = 30
Q. What is the difference between struct and class in C++?
β
Correct Answer: (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.
Q. Predict the output of following C++ program.
#include<iostream>
using namespace std;
class Empty {};
int main() {
cout << sizeof(Empty);
return 0;
}
β
Correct Answer: (A)
A non-zero value
Q. class Test {
int x;
};
int main() {
Test t;
cout << t.x;
return 0;
}
β
Correct Answer: (C)
Compiler Error
Q. Which of the following is true?
β
Correct Answer: (B)
Objects of a class do not share non-static members. Every object has its own copy.
Q. A member function can always access the data in __________, (in C++).
β
Correct Answer: (A)
the class of which it is member
Q. Which of the following is not correct for virtual function in C++?
β
Correct Answer: (B)
Virtual function can be static.
Q. 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
β
Correct Answer: (C)
(2), (3), (4)
Q. Which of the following cannot be passed to a function in C++?
β
Correct Answer: (D)
Header file
Q. Which of the following, in C++, is inherited in a derived class from base class?
β
Correct Answer: (C)
Data members
Jump to