C++ MCQs with answers Page - 101

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 syntax to override the + operator for class A?

  • (A) int +(arguments){}
  • (B) int [+](arguments){}
  • (C) A operator+(arguments){}
  • (D) A operator[+](arguments){}

A

Admin • 833.24K Points
Coach

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

Code:
#include<iostream> 
using namespace std; 
  
class MyClass
{ 
  public: 
    MyClass(); 
}; 
  
MyClass::MyClass()  { 
    cout << "Constructor is called
"; 
} 
  
int main() 
{ 
    cout << " Before 
"; 
    MyClass myclass(); 
    cout << " After 
"; 
    return 0; 
}
  • (A) Before Constructor is called After
  • (B) Before After
  • (C) Constructor is called Before After
  • (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 val; 
public: 
    MyClass (int v = 0) {val = v;} 
    int getValue() { return val; } 
}; 
  
int main() { 
    const MyClass obj;   
    cout << obj.getValue(); 
    return 0; 
}
  • (A) 0
  • (B) Random value
  • (C) Compilation error
  • (D) None of these

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 &val; 
public: 
    MyClass (int &v) { val = v; } 
    int getValue() { return val; } 
}; 
  
int main() 
{ 
    int v = 10; 
    MyClass obj(v); 
    cout << obj.getValue() << " "; 
    v = 20; 
    cout << obj.getValue() << endl; 
    return 0; 
}
  • (A) 10
  • (B) 20
  • (C) 10 20
  • (D) Compilation error

A

Admin • 833.24K Points
Coach

Q. An exception is generated using the keyword __________

  • (A) throws
  • (B) throw
  • (C) threw
  • (D) Thrown

A

Admin • 833.24K Points
Coach

Q. If the default constructor is not defined, how will the objects of the class be created?

  • (A) An error will occur at runtime.
  • (B) The compiler will generate an error.
  • (C) The compiler provides its default constructor to build the object.
  • (D) None of the above

A

Admin • 833.24K Points
Coach

Q. What is the output of the following code?

Code:
#include <iostream> 
using namespace std; 
  
class MyClass { 
private: 
  static const int val = 10; 
public: 
  static int getValue() { return val; } 
}; 
  
int main() { 
  cout << MyClass::getValue() << endl; 
  return 0; 
}
  • (A) 10
  • (B) 0
  • (C) Compilation error
  • (D) None of the above

A

Admin • 833.24K Points
Coach

Q. Is it mandatory to call a constructor to create an object?

  • (A) Yes
  • (B) No
  • (C) NA
  • (D) NA

A

Admin • 833.24K Points
Coach

Q. Choose another definition for objects:

  • (A) Class Member
  • (B) Class associate
  • (C) Class attribute
  • (D) Instance of a class

A

Admin • 833.24K Points
Coach

Q. How many objects can be in the same class?

  • (A) 1
  • (B) 2
  • (C) 3
  • (D) As much as possible

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