A
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 QuestionA
A
#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
#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
#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
A
A
#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
A
A
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