
Q61
Q61 Given the C++ code:
int *ptr = new int(5);
*ptr = 10;
delete ptr;,
what does this code do?
Allocates memory for an integer, sets it to 10, then releases the memory
Causes a memory leak
Generates a runtime error
Allocates memory for an integer without releasing it
Q62
Q62 Spot the error:
int *ptr;
*ptr = new int;
*ptr = 5;
delete ptr;
Dereferencing an uninitialized pointer
Syntax error in memory allocation
No error
Incorrect use of delete
Q63
Q63 What is a class template in C++?
A class defined inside another class
A class that serves as a blueprint for creating other classes
A class that can handle multiple data types generically
A class used exclusively for STL operations
Q64
Q64 How does the std::map container in C++ STL store elements?
In a single list
In key-value pairs, with unique keys
As an array of elements
In a stack-like structure
Q65
Q65 What is the primary difference between std::list and std::vector in C++ STL?
std::list is for integer types only, while std::vector can hold any type
std::list provides sequential access, while std::vector provides random access
std::list is a dynamic array, while std::vector is a linked list
std::list is a doubly linked list, while std::vector is a dynamic array
Q66
Q66 What distinguishes std::set from other STL containers?
It allows for rapid insertion of elements
It automatically sorts the elements in ascending order
It stores each element in duplicate
It is the only STL container that uses templates
Q67
Q67 Identify the issue in this C++ code:
std::vector
for (int i = 0; i <= v.size(); ++i) {
cout << v[i]; }
Using a wrong loop condition
Accessing elements outside the vector's bounds
Incorrect use of the vector container
No error
Q68
Q68 Which block of code is used to handle exceptions in C++?
try block
catch block
throw block
error block
Q69
Q69 What is the use of the std::exception class in C++?
To terminate a program
To catch syntax errors
As a base class for standard exception types
To declare new variables
Q70
Q70 What is the output of this code?
try { throw 20; } catch (int e) {
cout << "An exception occurred. Exception Nr. " << e;
}
An error message
An exception occurred. Exception Nr. 20
20
The program crashes
Q71
Q71 Given the C++ code snippet:
try { int* myarray = new int[1000]; } catch (std::bad_alloc& e) {
cout << "Allocation failed: " << e.what();
},
what does this code do?
It handles an out-of-memory error
It creates an array of 1000 integers
It throws a bad_alloc exception
It catches syntax errors
Q72
Q72 Identify the issue in this code:
try { throw "Error occurred"; } catch (...) {
cout << "An error occurred";
}
The catch block does not specify the exception type
The throw statement is incorrect
There is no error
The try block is empty
Q73
Q73 What is the purpose of namespaces in C++?
To optimize code execution speed
To handle exceptions
To avoid name conflicts in larger programs
To manage dynamic memory
Q74
Q74 What are smart pointers in C++?
Pointers that automatically manage memory allocation and deallocation
Pointers that increase execution speed
Arrays with advanced features
Iterators in the STL
Q75
Q75 What is a lambda expression in C++?
A function that cannot have its address taken
A compact way of defining anonymous functions
A template for creating multiple functions
A method in the STL
Q76
Q76 How is multithreading achieved in C++?
Using the std::thread library
By creating multiple processes
Through lambda expressions
By using dynamic memory allocation
Q77
Q77 In C++, which smart pointer type automatically deallocates the memory when it is no longer in use?
auto_ptr
shared_ptr
unique_ptr
weak_ptr
Q78
Q78 What is the significance of std::regex in C++?
It is used for creating regular expressions
It is a class template for sequence containers
It is a function for memory allocation
It is a method for string manipulation
Q79
Q79 Given the C++ code snippet:
auto lambda = [](int x, int y) { return x + y; }; cout << lambda(2, 3);,
what is the output?
5
Compilation error
2
3
Q80
Q80 What is an object in object-oriented programming?
A code snippet
A variable
An instance of a class
A function
Q81
Q81 Which of the following is a feature of procedure-oriented programming?
Class-based
Focus on functions
Inheritance
Polymorphism
Q82
Q82 Which principle of OOP is illustrated by defining different methods with the same name but different parameters?
Inheritance
Polymorphism
Encapsulation
Abstraction
Q83
Q83 What distinguishes a class from an object in OOP?
A class is a blueprint, while an object is an instance of a class
A class cannot contain methods, while an object can
Objects are templates, while classes are real entities
There is no difference
Q84
Q84 Consider the following code snippet:
class Animal { public: void eat() { cout << "Eating..."; } };
What is demonstrated in this code?
Inheritance
Encapsulation
Class definition
Polymorphism
Q85
Q85 Identify the issue in this C++ code snippet:
class Car {
public:
int speed;
void Car() { speed = 0; }
};
Incorrect class constructor syntax
Missing data encapsulation
No error
Inheritance misuse
Q86
Q86 Which of these is not a fundamental data type in C++?
int
float
string
char
Q87
Q87 What is the output of the expression 5 + 3 * 2 in C++?
16
11
10
8
Q88
Q88 What does the ++ operator do in C++?
Divides the value by two
Decreases the value by one
Increases the value by one
Squares the value
Q89
Q89 What is the result of the expression !true && false in C++?
true
false
Syntax error
None of the above
Q90
Q90 What is the result of int x = 10; x *= 3; in C++?
30
13
33
10


