Explore topic-wise MCQs in C++ Programming.

This section includes 8 Mcqs, each offering curated multiple-choice questions to sharpen your C++ Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the output of this program?
#include <iostream>
using namespace std;
struct N
{
int k;
char ch;
float p;
void function();
};
void N :: function() {}
struct M
{
public:
int k;
char ch;
float p;
void function();
};
void M :: function() {}
int main()
{
N obj1; M obj2;
obj1.k = obj2.k = 2;
obj1.ch = obj2.ch = 'U';
obj1.p = obj2.p = 5.125;
obj1.function();
obj2.function();
cout << "Value Allocated in memory...";
return 0;
}

A. Compilation Error
B. Runtime Error
C. Value Allocated in memory...
D. 2 U 5.125
E. None of these
Answer» D. 2 U 5.125
2.

What is the output of this program?
#include <iostream>
using namespace std;
class Employee
{
public:
int IdNo , Salary , bonus ;
protected:
void get()
{
IdNo = 101, Salary = 15000, bonus = 5000;
}
};
class Extra
{
public:
int Gift;
void getGift()
{
Gift = 4000;
}
};
class statement : public Employee, public Extra
{
int GrandTotal, Average;
public:
void display()
{
GrandTotal = (Salary + bonus);
Average = GrandTotal / 2;
cout << GrandTotal << " ";
cout << Average;
}
void setObject()
{
get();
}
};
int main()
{
statement object;
object.setObject();
object.getGift();
object.display();
}

A. 15000 5000
B. 5000 15000
C. 4000 15000
D. 10000 20000
E. 20000 10000
Answer» F.
3.

What is the output of this program?
#include <iostream>
using namespace std;
class Abhay
{
public:
int age;
};
int main()
{
Abhay obj;
obj.age = 24;

cout << "Abhay is " ;
cout << obj.age << " years old.";
}

A. years old.
B. 24
C. Abhay is
D. Abhay is 24 years old.
E. None of these
Answer» E. None of these
4.

What is the output of this program?
#include <iostream>
using namespace std;
struct A;
struct B
{
void fun1(A*);
};
struct A
{
private:
int k;
public:
void initialize();
friend void fun2(A* , int);
friend void B :: fun1(A*);
friend struct C;
friend void fun3();
};
void A :: initialize()
{
k = 0;
}
void fun2(A* a, int k)
{
a -> k = k;
}
void B :: fun1(A * a)
{
a -> k = 35;
cout << a->k;
}
struct C
{
private:
int L;
public:
void initialize();
void fun2(A* a);
};
void C::initialize()
{
L = 45;
}
void C::fun2(A* a)
{
a -> k += L;
}
void fun3()
{
A a;
a.k = 150;
cout << a.k;
}
int main()
{
A a;
C c;
c.fun2(&a);
cout << "Data accessed";
}

A. Data accessed
B. Compilation Error
C. Garbage value
D. Runtime Error
E. None of these
Answer» B. Compilation Error
5.

What is the output of this program?
#include <iostream>
using namespace std;
struct N
{
private:
int p, q, s;
public:
int fun1();
void fun2();
};
int N :: fun1()
{
return p + q + s;
}
void N :: fun2()
{
p = q = s = 0;
}
class M
{
int p, q, s;
public:
int fun1();
void fun2();
};
int M :: fun1()
{
return p + q + s;
}
void M :: fun2()
{
p = q = s = 0;
}
int main()
{
N obj1;
M obj2;
obj1.fun1();
obj1.fun2();
obj2.fun1();
obj2.fun2();
cout << "Identical results...";
}

A. Compilation Error
B. Runtime Error
C. Garbage value
D. Identical results...
E. None of these
Answer» E. None of these
6.

What is the importance of mutable keyword?

A. It will not allow the data member to change within a const member function
B. It will copy the values of the variable
C. It allows the data member to change within a const member function
D. All of above
E. None of these
Answer» D. All of above
7.

What is the default access level to a block of data?

A. Protected
B. Private
C. Public
D. All of above
E. None of these
Answer» C. Public
8.

How many access specifiers are there in c++?

A. 4
B. 3
C. 2
D. 1
E. None of these
Answer» C. 2