C++ MCQs with answers Page - 99

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 does a class contain in C++?

  • (A) Data
  • (B) Functions
  • (C) Data and Functions
  • (D) Arrays

A

Admin • 833.24K Points
Coach

Q. How many access specifiers are there?

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

A

Admin • 833.24K Points
Coach

Q. ___ is used to define a member of a class externally?

  • (A) #
  • (B) ::
  • (C) !! $
  • (D) :

A

Admin • 833.24K Points
Coach

Q. What operator does a pointer object of a class use to access its data members and member functions?

  • (A) ::
  • (B) .
  • (C) ->
  • (D) :

A

Admin • 833.24K Points
Coach

Q. Suppose the integers take 4 bytes, what is the output of the following code?

Code:
#include<iostream>
  
using namespace std;    
  
class MyClass
{ 
  static int a; 
  int b; 
}; 
  
int MyClass::a; 
  
int main() 
{ 
    cout << sizeof(MyClass); 
    return 0; 
}
  • (A) 4
  • (B) 8
  • (C) 16
  • (D) None of the above

A

Admin • 833.24K Points
Coach

Q. What is the output of the following C++ code?

Code:
#include <iostream>
using namespace std;
class MyClass
{
  int var;
 
   public:
  int write(int i) const {
    var = i;
  }
  int read() const {
    return var;
  }
};
int main(int argc, char const *argv[])
{
  MyClass obj;
  obj.write(2);
  cout << obj.read();
}
  • (A) 2
  • (B) 3
  • (C) Compilation error
  • (D) None of the above

A

Admin • 833.24K Points
Coach

Q. What is the output of the following C++ code?

Code:
#include <iostream>

using namespace std;

class calculate {
    int x, y;
  
    public:
    void val(int, int);
    int sum() {
        return (x + y);
    }
};
void calculate::val(int a, int b) {
    x = a;
    y = b;
}
int main() {
    calculate calculate;
    calculate.val(5, 10);
    cout << "The sum = " << calculate.sum();
    return 0;
}
  • (A) The sum = 5
  • (B) The sum = 10
  • (C) The sum = 15
  • (D) Error because calculate is used as class name and variable name in line 19.

A

Admin • 833.24K Points
Coach

Q. Which one is a valid class declaration?

  • (A) public classe A {}
  • (B) classe A {}
  • (C) classe A {int x;};
  • (D) object A {int x;};

A

Admin • 833.24K Points
Coach

Q. The members of a class in C++ are by default __________

  • (A) private
  • (B) protected
  • (C) public
  • (D) public and protected

A

Admin • 833.24K Points
Coach

Q. What is the correct syntax to access a static member of a class?

Code:
class A
{
  public:
    static int val;
}
  • (A) A->val
  • (B) A.val
  • (C) A::val
  • (D) A^val

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