Explore topic-wise MCQs in C++ Programming.

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

51.

What is the output of this program?
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
priority_queue<int> QueueData;
QueueData.push(12);
QueueData.push(25);
QueueData.push(13);
cout << QueueData.top() << endl;
return 0;
}

A. 12
B. 25
C. 13
D. All of above
E. None of these
Answer» C. 13
52.

What is the output of this program?
#include <iostream>
#include <stack>
using namespace std;
int main ()
{
stack<int> StackData;
StackData.push(25);
StackData.push(45);
StackData.top() -= 5;
cout << StackData.top() << endl;
return 0;
}

A. 45
B. 25
C. 5
D. Compilation Error
E. None of these
Answer» B. 25
53.

What is the output of this program?
#include <iostream>
#include <stack>
using namespace std;
int main ()
{
stack<int> StackData;
cout << (int) StackData.size();
for (int k =0; k < 5; k++)
{
StackData.push(k);
cout << " ";
cout << (int) StackData.size() << " ";
}
return 0;
}

A. 0 1
B. 0 1 2
C. 0 1 2 3
D. 0 1 2 3 4
E. 0 1 2 3 4 5
Answer» F.
54.

What is the output of this program?
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
priority_queue<int> QueueData;
QueueData.push(25);
QueueData.push(75);
QueueData.push(45);
QueueData.push(55);
while (!QueueData.empty())
{
cout << " " << QueueData.top();
QueueData.pop();
}
cout << endl;
return 0;
}

A. 75 65 55 45 25
B. 75 65 55 45
C. 75 65 55
D. 75 65
E. 75
Answer» B. 75 65 55 45
55.

What is the output of this program?
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
queue<int> QueueData;
int add (0);
for (int k = 1; k <= 50; k++)
QueueData.push(k);
while (!QueueData.empty())
{
add += QueueData.front();
QueueData.pop();
}
cout << add << endl;
return 0;
}

A. 75
B. 1275
C. 12
D. Compilation Error
E. None of these
Answer» C. 12
56.

What is the output of this program?
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
queue<int> QueueData;
QueueData.push(15);
QueueData.push(45);
QueueData.back() -= QueueData.front();
cout << QueueData.back() << endl;
return 0;
}

A. 15
B. 45
C. 30
D. Compilation Error
E. None of these
Answer» D. Compilation Error
57.

What is the output of this program?
#include <iostream>
#include <cmath>
#include <list>
using namespace std;
bool IntegralPart(double One, double Two)
{
return ( int(One) == int(Two) );
}
struct is_near
{
bool operator() (double One, double Two)
{
return (fabs(One - Two) < 5.0);
}
};
int main ()
{
double Array[] = { 10.05, 3.70, 12.02, 10.25, 14.24, 11.47, 76.32, 82.35, 95.31, 52.95 };
list<double> ListData(Array, Array + 8);
ListData.sort();
ListData.unique();
ListData.unique (IntegralPart);
ListData.unique (is_near());
for (list<double> :: iterator iter = ListData.begin(); iter != ListData.end(); ++iter)
cout << ' ' << *iter;
cout << ' n';
return 0;
}

A. 10.05 3.70 12.02 10.25
B. 14.24 11.47 76.32 82.35
C. 82.35 95.31 52.95
D. 3.7 10.05 76.32 82.35
E. None of these
Answer» E. None of these
58.

What is the output of this program?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> VectorData;
int * ptr;
unsigned int k;
ptr = VectorData.get_allocator().allocate(6);
for (k = 0; k < 6; k++)
VectorData.get_allocator().construct(&ptr[k], k);
for (k = 0; k < 6; k++)
cout << ' ' << ptr[k];
for (k = 0; k < 6; k++)
VectorData.get_allocator().destroy(&ptr[k]);
VectorData.get_allocator().deallocate(ptr, 6);
return 0;
}

A. 0 1
B. 0 1 2
C. 0 1 2 3
D. 0 1 2 3 4
E. 0 1 2 3 4 5
Answer» F.
59.

What is the output of this program?
#include <iostream>
#include <deque>
using namespace std;
int main ()
{
unsigned int k;
deque<int> DequeData;
DequeData.push_back (50);
DequeData.push_back (75);
DequeData.push_back (90);
for(deque<int> :: iterator iter = DequeData.begin(); iter != DequeData.end(); ++iter)
{
}
DequeData.clear();
DequeData.push_back (150);
DequeData.push_back (175);
for(deque<int> :: iterator iter = DequeData.begin(); iter != DequeData.end(); ++iter)
cout << ' ' << *iter;
cout << ' n';
return 0;
}

A. 50 75
B. 75 90
C. 90 150
D. 150 175
E. None of these
Answer» E. None of these
60.

What is the output of this program?
#include <iostream>
#include <deque>
using namespace std;
int main ()
{
deque&ltint> DequeData (6);
deque<int>::reverse_iterator RevIter = DequeData.rbegin();
int k = 0;
for (RevIter = DequeData.rbegin(); RevIter != DequeData.rend(); ++RevIter)
*RevIter = ++k;
for (deque<int> :: iterator iter = DequeData.begin();
iter != DequeData.end(); ++iter)
cout << ' ' << *iter;
return 0;
}

A. 6 5
B. 6 5 4
C. 6 5 4 3
D. 6 5 4 3 2
E. 6 5 4 3 2 1
Answer» F.
61.

What is the output of this program?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> VectorData (6);
int* ptr = VectorData.data();
*ptr = 30;
++ptr;
*ptr = 15;
ptr[2] = 150;
for (unsigned k = 0; k < VectorData.size(); ++k)
cout << ' ' << VectorData[k];
return 0;
}

A. 30 15 0 150 0 0
B. 30 15 0 150 0
C. 30 15 0 150
D. 30 15 0
E. 30 15
Answer» B. 30 15 0 150 0
62.

What is the output of this program?
#include 
using namespace std;
int Fun(int p, int q)
{
int res;
res = 0;
while (q != 0)
{
res = res + p;
q = q - 2;
}
return(res);
}
int main ()
{
int p = 12, q = 10;
cout << Fun(p, q) ;
return(0);
}

A. 60
B. 12
C. 10
D. Compilation Error
E. None of these
Answer» B. 12
63.

What is the output of this program?
#include 
using namespace std;
int max(int p, int q)
{
return ( p > q ? p : q);
}
int main()
{
int m = 15;
int n = 16;
cout << max(m, n);
return 0;
}

A. Compilation Error
B. Runtime Error
C. Garbage value
D. 15
E. 16
Answer» F.
64.

What is the output of this program?
#include 
using namespace std;
double Time()
{
double T = 26.25;
double H = T;
return H;
}
int main()
{
double H = Time();
cout << "Weekly Hours: " << H;
return 0;
}

A. Compilation Error
B. Runtime Error
C. Garbage value
D. Weekly Hours: 0
E. Weekly Hours: 26.25
Answer» F.
65.

What is the output of this program?
#include 
using namespace std;
int GCD(int p, int q)
{
int temp;
while (q != 0)
{
temp = p % q;
p = q;
q = temp;
}
return(p);
}
int main ()
{
int m = 10, n = 120;
cout << GCD(m, n);
return(0);
}

A. 10
B. 120
C. Compilation Error
D. Runtime Error
E. None of these
Answer» B. 120
66.

What will be the output of these two programs?
(i)
#ifndef Example_H
#define Example_H
int n = 251;
#endif

(ii)
#include 
#include "Example.h"
using namespace std;
int main(int argc, char * argv[] )
{
cout << num++;
return 0;
}

A. 252
B. 251
C. Compilation Error
D. Runtime Error
E. None of these
Answer» C. Compilation Error
67.

What is the output of this program?
#include 
using namespace std;
int main()
{
typedef int number;
typedef char name;
name n = "Interview Mania";
number P = 12, Q = 25;
number R = P + n;
cout << R;
return 0;
}

A. Interview Mania12
B. 25Interview Mania
C. Compilation Error
D. Garbage Value
E. Runtime Error
Answer» D. Garbage Value
68.

What is the output of this program?
#include 
using namespace std;
int main()
{
char ch[30];
cout << "Enter Name: ";
gets(ch);
cout << "Name: ";
puts(ch);
return 0;
}

A. Runtime Error
B. Garbage value
C. Exception occur
D. Compilation Error
E. None of these
Answer» E. None of these
69.

What is the output of this program?
 #include <iostream>
#include <vector>
#include <iterator>
#include <stddef.h>
using namespace std;
template<class myType>
class Container
{
public:
Container(size_t xDim, size_t yDim, myType const& defaultValue)
: objData(xDim * yDim, defaultValue)
, xSize(xDim)
, ySize(yDim)
{
}
myType& operator()(size_t x, size_t y)
{
return objData[y * xSize + x];
}
myType const& operator()(size_t x, size_t y) const
{
return objData[y * xSize + x];
}
int getSize()
{
return objData.size();
}
void inputEntireVector(vector<myType> inputVector)
{
objData.swap(inputVector);
}
void printContainer(ostream& stream)
{
copy(objData.begin(), objData.end(),
ostream_iterator<myType>(stream, ""/*No Space*/));
}
private:
vector<myType> objData;
size_t xSize;
size_t ySize;
};
template<class myType>
inline ostream& operator< {
object.printContainer(stream);
return stream;
}
void ContainerInterfacing();
int main()
{
ContainerInterfacing();
return 0;
}
void ContainerInterfacing()
{
static int const ConsoleWidth = 95;
static int const ConsoleHeight = 30;
size_t width = ConsoleWidth;
size_t height = ConsoleHeight;
Container<int> mySimpleContainer(width, height, 0);
cout << mySimpleContainer.getSize() << endl;
mySimpleContainer(0, 0) = 4;
}

A. 2850
B. No Space
C. Depends on the compiler
D. Compilation Error
E. None of these
Answer» D. Compilation Error
70.

What is the output of this program?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> Data;
Data.assign (5,50);
vector<int>::iterator iter;
iter=Data.begin()+1;
int Array[] = {1200,20,40};
cout << int (Data.size()) << ' n';
return 0;
}

A. 5
B. 50
C. 20
D. 40
E. None of these
Answer» B. 50
71.

What is the output of this program?
#include <iostream>
#include <vector>
using namespace std;
class ComponentClass
{
public:
virtual void traverse() = 0;
};
class LeafClass: public ComponentClass
{
int number;
public:
LeafClass(int num)
{
number = num;
}
void traverse()
{
cout << number << ' ';
}
};
class CompositeClass: public ComponentClass
{
vector < ComponentClass * > children;
public:
void add(ComponentClass *ptr)
{
children.push_back(ptr);
}
void traverse()
{
for (int k = 0; k < children.size(); k++)
children[k]->traverse();
}
};
int main()
{
CompositeClass containers[6];
for (int k = 0; k < 5; k++)
for (int L = 0; L < 4; L++)
containers[k].add(new LeafClass(k *4+L));
for (int m = 1; m < 5; m++)
containers[0].add(&(containers[m]));
for (int n = 0; n < 5; n++)
{
containers[n].traverse();
cout << endl;
}
}

A. 4 5 6 7
B. 8 9 10 11
C. 12 13 14 15
D. 16 17 18 19
E. None of these
Answer» F.
72.

What is the output of this program?
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
try
{
char *ptr;
strcpy(ptr, "Who are u?");
}
catch(const exception& excep)
{
}
}

A. Compilation Error
B. Who are u?
C. Runtime Error
D. segmentation fault
E. None of these
Answer» E. None of these
73.

What is the output of this program?
#include <iostream>
#include <exception>
using namespace std;
class BaseClass
{
virtual void dummy() {}
};
class DerivedClass: public BaseClass
{
int num;
};
int main ()
{
try
{
BaseClass * ptr1 = new DerivedClass;
BaseClass * ptr2 = new BaseClass;
DerivedClass * ptr3;
ptr3 = dynamic_cast(ptr1);
if (ptr3 == 0)
cout << "Null pointer on first type-cast" << endl;
ptr3 = dynamic_cast(ptr2);
if (ptr3 == 0)
cout << "Null pointer on second type-cast" << endl;
}
catch (exception& excep)
{
cout << "Exception: " << excep.what();
}
return 0;
}

A. Null pointer on first type-cast
B. Null pointer on second type-cast
C. Exception:
D. All of above
E. None of these
Answer» C. Exception:
74.

What is the output of this program?
#include <iostream>
#include <typeinfo>
#include <exception>
using namespace std;
class BaseClass
{
virtual void f(){}
};
class DerivedClass : public BaseClass {};
int main ()
{
try
{
BaseClass* ptr1 = new BaseClass;
BaseClass* ptr2 = new DerivedClass;
cout << typeid(*ptr1).name() << " ";
cout << typeid(*ptr2).name();
}
catch (exception& excep)
{
cout << "Exception: " << excep.what() << endl;
}
return 0;
}

A. 9BaseClass
B. 12DerivedClass
C. 9 12
D. Both 9BaseClass and 12DerivedClass
E. None of these
Answer» E. None of these
75.

What is the output of this program?
#include <iostream>
#include <typeinfo>
using namespace std;
int main ()
{
int * num1;
int num2;
num1 = 0; num2 = 3;
if (typeid(num1) != typeid(num2))
{
cout << typeid(num1).name() << " ";
cout << typeid(num2).name();
}
return 0;
}

A. i iP
B. iP i
C. Pi i
D. All of above
E. None of these
Answer» D. All of above
76.

What is the output of this program?
#include <typeinfo>
#include <iostream>
using namespace std;
class N
{
public:
virtual ~N();
};
int main()
{
N* ptr = NULL;
try
{
cout << typeid(*ptr).name() << endl;
}
catch (bad_typeid)
{
cout << "Object is NULL" << endl;
}
}

A. NULL
B. Compilation Error
C. Runtime Error
D. Object is NULL
E. None of these
Answer» E. None of these
77.

What is the output of this program?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> VectorData;
int add (0);
VectorData.push_back (50);
VectorData.push_back (150);
VectorData.push_back (200);
while (!VectorData.empty())
{
add += VectorData.back();
VectorData.pop_back();
}
cout << add << ' n';
return 0;
}

A. 50
B. 150
C. 200
D. 400
E. None of these
Answer» E. None of these
78.

What is the output of this program?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
unsigned int k;
vector<int> One;
vector<int> Two (3, 50);
vector<int> Three (Two.begin(), Two.end());
vector<int> Four (Three);
int Array[] = {10, 12, 71, 38};
vector<int> Five (Array, Array + sizeof(Array) / sizeof(int) );
for (vector<int> :: iterator it = Five.begin(); it != Five.end(); ++it)
cout << ' ' << *it;
return 0;
}

A. 10 12 71 38
B. 10 12 71
C. 10 12
D. 10
E. None of these
Answer» B. 10 12 71
79.

What is the output of this program?
#include <iostream>
using namespace std;
int StaticFunction(int)
{
int sum = 0;
sum = sum + 12;
return sum;
}
int main(void)
{
int num = 5, Res;
Res = StaticFunction(Res);
cout << Res << endl;
return 0;
}

A. 12
B. Compilation Error
C. Runtime Error
D. 5
E. None of these
Answer» B. Compilation Error
80.

What is the output of this program?
#include <iostream>
#include <new>
using namespace std;
int main ()
{
int k, num;
int * ptr;
num = 3;
ptr= new (nothrow) int[num];
if (ptr == 0)
cout << "Error: memory could not be allocated";
else
{
for (k=0; k {
ptr[num] = 7;
}
for (k = 0; k < num; k++)
cout << ptr[num] << " ";
delete[] ptr;
}
return 0;
}

A. 3
B. 7
C. 7 7
D. 7 7 7
E. None of these
Answer» E. None of these
81.

What is the output of this program?
#include 
using namespace std;
int main()
{
int i;
enum MonthName
{
January,February,March,April,May,June,July,August,September,October,November,December
};
for (i = February; i <= November; i++)
cout << i;
return 0;
}

A. 12345678910
B. 012345678910
C. 109876543210
D. Compilation Error
E. None of these
Answer» B. 012345678910
82.

What is the output of this program?
#include 
using namespace std;
int main()
{
typedef int number;
number P = 25, Q = 12;
number R = P + Q + P - Q;
cout << R;
return 0;
}

A. 25
B. 12
C. 50
D. Compilation Error
E. None of these
Answer» D. Compilation Error
83.

What is the use of vector arithmetic in c++?

A. Webdesign
B. Computer graphics
C. Computer booting
D. Both Computer graphics & Computer booting
E. None of these
Answer» C. Computer booting
84.

Which function is used to optimize the space in vector?

A. operator
B. at
C. bool
D. All of above
E. None of these
Answer» D. All of above
85.

What will be the type of output of vector cross product?

A. function
B. Scalar
C. Vector
D. Both Scalar & Vector
E. None of these
Answer» D. Both Scalar & Vector
86.

What is meant by permutation in c++?

A. To find all the combination of the range
B. To find all the values & combination in the range
C. To find all the values in the range
D. All of above
E. None of these
Answer» B. To find all the values & combination in the range
87.

What is meant by hash tables in C++?

A. Data structure
B. Array data structure
C. Keyed array data structure
D. All of above
E. None of these
Answer» D. All of above
88.

How many categories of iterators are there in c++?

A. 5
B. 4
C. 3
D. 2
E. 1
Answer» B. 4
89.

How many parameters are required for sort_heap function?

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

What type of algorithm is not available in creating our own STL style algorithms?

A. sort
B. copy_if()
C. remove_copy_if()
D. All of above
E. None of these
Answer» C. remove_copy_if()
91.

Pick out the in correct type of function in header file.

A. Sort
B. Join
C. Partitions
D. Merge
E. None of these
Answer» C. Partitions
92.

How many parameters are required for next_permutation?

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

What is the header file for vector permutation?

A. <algorithm>
B. vector_permutation
C. vector_perm
D. vector_permutation.h
E. None of these
Answer» B. vector_permutation
94.

How many adaptors support the checked iterators?

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

What will happen if the iterator is unchecked?

A. Arising of compiler warnings & Unchecked behavior on program
B. Nothing will execute
C. Unchecked behavior on program
D. Arising of compiler warnings
E. None of these
Answer» B. Nothing will execute
96.

What type of reference should be used in vector arithmetic?

A. Single
B. dynamic
C. const
D. both dynamic & const
E. None of these
Answer» D. both dynamic & const
97.

What is the use of checked iterators?

A. It will check the list value
B. Overwrite the bounds of your container
C. Not allow you to overwrite the bounds of your container
D. All of above
E. None of these
Answer» D. All of above
98.

By using which operator does point to next element is represent in iterator?

A.
B. +-
C. ++
D. All of above
E. None of these
Answer» D. All of above
99.

In which type of semantics does c++ implements iterator?

A. Pointer
B. Memory
C. Size
D. All of above
E. None of these
Answer» B. Memory
100.

Which header file is used to manipulate the vector algebra in c++?

A. vmath
B. math
C. cmath
D. All of above
E. None of these
Answer» B. math