Explore topic-wise MCQs in C++ Programming.

This section includes 20 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>
#include <new>
using namespace std;
struct N
{
virtual ~N() { };
void operator delete(void* ptr1)
{
cout << "N :: operator delete" << endl;
}
};
struct M : N
{
void operator delete(void* ptr1)
{
cout << "M :: operator delete" << endl;
}
};
int main()
{
N* ptr2 = new M;
delete ptr2;
}

A. Compilation Error
B. N :: operator delete
C. M :: operator delete
D. Runtime Error
E. None of these
Answer» D. Runtime Error
2.

What is the output of this program?
#include &ltiostream>
#include <memory>
#include <string>
using namespace std;
int main ()
{
pair <string*, ptrdiff_t> Res = get_temporary_buffer<string>(5);
if (Res.second > 0)
{
uninitialized_fill ( Res.first, Res.first + Res.second,
"Bye " );
for (int k = 0; k < Res.second; k++)
cout << Res.first[k] ;
return_temporary_buffer(Res.first);
}
return 0;
}

A. Bye
B. Bye Bye Bye
C. Bye Bye Bye Bye Bye
D. Bye Bye
E. Bye Bye Bye Bye
Answer» D. Bye Bye
3.

What is the output of this program?
#include <iostream>
#include <memory>
#include <string>
using namespace std;
int main ()
{
string str[] = {"Interveiw", "Mania"};
pair <string*, ptrdiff_t> Res = get_temporary_buffer<string>(2);
if (Res.second>0)
{
uninitialized_copy ( str, str + Res.second, Res.first );
for (int k = 0; k < Res.second; k++)
cout << Res.first[k] << " ";
return_temporary_buffer(Res.first);
}
return 0;
}

A. Compilation Error
B. Interveiw
C. Mania
D. Interveiw Mania
E. None of these
Answer» E. None of these
4.

What is the output of this program?
#include <iostream>
#include <memory>
#include <algorithm>
using namespace std;
int main ()
{
int num[] = {11, 15, 14, 15, 14, 11};
pair <int*, ptrdiff_t> Res = get_temporary_buffer<int>(6);
if (Res.second > 0)
{
uninitialized_copy (num, num + Res.second, Res.first);
sort (Res.first, Res.first + Res.second);
for (int k = 0; k < Res.second; k++)
cout << Res.first[k] << " ";
return_temporary_buffer (Res.first);
}
return 0;
}

A. 11 11
B. 11 11 14
C. 11 11 14 14 15 15
D. 14 15 15
E. 14 15
Answer» D. 14 15 15
5.

What is the output of this program?
#include <iostream>
#include <new>
#include <cstdlib>
using namespace std;
const int bsize = 128;
int *ptr1;
bool allocate = true;
void get_memory()
{
cerr << "free store exhausted" << endl;
delete [] ptr1;
allocate = false;
}
void eat_memory(int size)
{
int *ptr2 = new int[size];
if (allocate)
eat_memory(size);
else
cerr << "free store addr = " << ptr2 << endl;
}
int main()
{
set_new_handler(get_memory);
ptr1 = new int[bsize];
cerr << "free store addr = " << ptr1 << endl;
eat_memory(bsize);
return 0;
}

A. Compilation Error
B. Segmentation fault
C. Free store addr
D. Runtime Error
E. None of these
Answer» C. Free store addr
6.

What is the output of this program?
#include <iostream> 
#include <ctype.h>
int main ()
{
int k = 0;
char str[] = "Ajit Kumar Gupta";
char ch;
while (str[k])
{
ch = str[k];
if (islower(ch))
ch = toupper(ch);
putchar (ch);
k++;
}
return 0;
}

A. AJIT KUMAR GUPTA
B. Ajit Kumar Gupta
C. Compilation Error
D. Runtime Error
E. None of these
Answer» B. Ajit Kumar Gupta
7.

What will the monetary facet will do?

A. Parsing of character values
B. Handle formatting and parsing of monetary values
C. Handle formatting and parsing of character values
D. All of above
E. None of these
Answer» C. Handle formatting and parsing of character values
8.

What kind of locale does every program is having in C++?

A. temp locale
B. local locale
C. global locale
D. All of above
E. None of these
Answer» D. All of above
9.

What is the main feature of locale in C++?

A. Portability
B. Reliability
C. Sustainability
D. All of above
E. None of these
Answer» D. All of above
10.

What is the correct syntax for declaring an allocator?

A. template < class T > class;
B. template class allocator;
C. template < class T > class allocator;
D. All of above
E. None of these
Answer» D. All of above
11.

What is the use of reference member type in allocator?

A. Reference to an element
B. Point to an element
C. Quantities of element
D. All of above
E. None of these
Answer» B. Point to an element
12.

Which header file is used to manipulate the allocater?

A. object
B. allocater
C. memory
D. All of above
E. None of these
Answer» D. All of above
13.

Which operator is used to deallocate the memory?

A. free
B. empty
C. destroy
D. All of above
E. None of these
Answer» B. empty
14.

Which operator is used to allocate the memory?

A. free
B. =
C. +
D. new
E. None of these
Answer» E. None of these
15.

Where are allocators implemented?

A. Standard library
B. C++ code library
C. Template library
D. All of above
E. None of these
Answer» B. C++ code library
16.

Which is used to allocate and deallocate storage for objects during the execution?

A. Freestore
B. Stack
C. Heap
D. All of above
E. None of these
Answer» B. Stack
17.

Which is used to pass the large objects in c++?

A. pass by reference
B. pass by value
C. both reference & pass by value
D. function
E. None of these
Answer» B. pass by value
18.

Where are allocators used?

A. Used for pointers
B. Allocation of memory
C. Deallocation of memory
D. Both Allocation & Deallocation of memory
E. None of these
Answer» E. None of these
19.

How can object be allocated outside the object lifetime?

A. float
B. void*
C. int
D. All of above
E. None of these
Answer» C. int
20.

What must be an operand of operator delete?

A. Array
B. Stack
C. Pointer
D. All of above
E. None of these
Answer» D. All of above