C++ MCQs with answers Page - 116

Here, you will find a collection of MCQ questions on C++. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 833.24K Points
Coach

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

A

Admin • 833.24K Points
Coach

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

A

Admin • 833.24K Points
Coach

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

  • (A) 0
  • (B) Garbage Value
  • (C) Compiler Error
  • (D) None

A

Admin • 833.24K Points
Coach

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

A

Admin • 833.24K Points
Coach

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

A

Admin • 833.24K Points
Coach

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

A

Admin • 833.24K Points
Coach

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

  • (A) (1)
  • (B) (2), (4)
  • (C) (2), (3), (4)
  • (D) (4)

A

Admin • 833.24K Points
Coach

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

  • (A) Constant
  • (B) Structure
  • (C) Array
  • (D) Header file

A

Admin • 833.24K Points
Coach

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

A

Admin • 833.24K Points
Coach

Q. Which of the following is a correct statement?

  • (A) Composition is a strong type of association between two classes with full ownership.
  • (B) Composition is a strong type of association between two classes with partial ownership.
  • (C) Composition is a weak type of association between two classes with partial ownership.
  • (D) Composition is a weak type of association between two classes with strong ownership.

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ