
Q121
Q121 Identify the error in this code:
int x = 5;
int *ptr;
*ptr = &x;
cout << *ptr;
Incorrect assignment to pointer
Syntax error
No error
Dereferencing an uninitialized pointer
Q122
Q122 What is a class in C++?
A blueprint for creating objects
A function in OOP
A variable type
An operator
Q123
Q123 What is the purpose of a constructor in a C++ class?
To initialize the class's member variables
To delete objects of the class
To allocate memory for objects
To declare a new class
Q124
Q124 How is abstraction different from encapsulation?
Abstraction hides complexity by showing only essential features, while encapsulation hides the internal state of an object
Abstraction and encapsulation are the same
Abstraction is used only in inheritance, while encapsulation is not
Encapsulation cannot be used in conjunction with polymorphism
Q125
Q125 Given the following C++ code, what is the output?
class MyClass { public: MyClass() {
cout << "Hello"; }
};
MyClass obj;
Hello
MyClass
Error
Nothing
Q126
Q126 Consider the code:
class Shape {
public:
virtual void draw() = 0;
}; class Circle : public Shape {
public: void draw() {
cout << "Circle"; }
};
What concept does this illustrate?
Encapsulation
Inheritance
Polymorphism
Abstraction
Q127
Q127 Pseudocode:
CLASS Rectangle PRIVATE width, height PUBLIC FUNCTION setDimensions(w, h) SET width TO w SET height TO h END What OOP concept is demonstrated here?
Encapsulation
Inheritance
Polymorphism
Abstraction
Q128
Q128 Pseudocode:
CLASS Shape ABSTRACT FUNCTION draw() END CLASS Circle EXTENDS Shape FUNCTION draw() PRINT "Circle" What does this illustrate?
Encapsulation
Abstraction
Inheritance
Polymorphism
Q129
Q129 Identify the mistake:
class Base {
public:
virtual void func() {} };
class Derived : public Base {
void func();
};
Missing function body in Derived
Incorrect use of virtual function
No error
Syntax error in class declaration
Q130
Q130 What is the primary purpose of the fstream library in C++?
To perform mathematical operations
To manage screen output
To handle file input and output
To process user input
Q131
Q131 Given the C++ code
ofstream file("example.txt");
file << "Hello, World!";
file.close();,
what does this code do?
Reads "Hello, World!" from example.txt
Writes "Hello, World!" to example.txt
Deletes "Hello, World!" from example.txt
Opens example.txt without modifying it
Q132
Q132 Pseudocode:
OPEN file.txt AS file WRITE "Data" TO file CLOSE file What is the primary action performed by this code?
Reading data from file.txt
Writing data to file.txt
Deleting data from file.txt
Creating a new file named file.txt
Q133
Q133 Spot the error:
ofstream file("example.txt");
file >> "Text";
file.close();
Wrong operator used for writing to file
File is not opened correctly
File is not closed properly
No error
Q134
Q134 What does the delete operator do in C++?
Deletes a variable from the program
Frees memory allocated by new
Removes a file from the disk
Erases a class definition
Q135
Q135 Which of the following statements about dynamic memory allocation is true?
Memory allocated by new is automatically deallocated
new and delete can only be used with primitive data types
new returns null if memory allocation fails
Dynamic memory allocation is less efficient than static allocation
Q136
Q136 What is memory leak in the context of dynamic memory allocation?
An error that occurs when memory allocation fails
The process of deleting unused memory
Memory that is not properly released after use
A special technique to clean memory
Q137
Q137 How can you prevent a memory leak in a C++ program?
By using automatic variables instead of dynamic variables
By ensuring every new operator is matched with delete
By avoiding the use of pointers
By only using static memory allocation
Q138
Q138 Identify the issue in this code:
int *arr = new int[5];
delete arr;
Incorrect syntax for deleting an array
No error
Memory leak
Access violation
Q139
Q139 What is a function template in C++?
A predefined function in the C++ Standard Library
A special function used for debugging
A way to create functions with a generic type
A container in the STL
Q140
Q140 Which STL container is typically used for implementing a dynamic array?
std::map
std::vector
std::list
std::set
Q141
Q141 In C++ STL, what is an iterator?
A loop that iterates over a container
A pointer-like object used to access elements in a container
A function to traverse arrays
A class template for container classes
Q142
Q142 Why are templates used in C++?
To create error-free code
To provide predefined functionality
To allow classes and functions to operate with generic types
To optimize code execution
Q143
Q143 Given the C++ code snippet:
template
return a + b;
}
What is this an example of?
A class template
A function template
An overloaded operator
An STL container
Q144
Q144 Spot the error:
template
T value; void setValue(T val) { value = val; }
};
Incorrect template syntax
Missing constructor
No error
Error in setValue function
Q145
Q145 What is the purpose of exception handling in C++?
To handle syntax errors in the code
To increase the execution speed of programs
To manage runtime errors in a controlled way
To debug the program
Q146
Q146 What keyword is used in C++ to throw an exception?
throw
error
exception
exit
Q147
Q147 What is the correct way to handle multiple exceptions in C++?
Using multiple throw statements
Using several try blocks
Using multiple catch blocks after a single try block
Using nested try-catch blocks
Q148
Q148 In C++, what happens if an exception is not caught?
The program will continue to execute
The exception gets rethrown automatically
The program terminates abnormally
The exception is ignored
Q149
Q149 Spot the error:
try { int x = -1;
if (x < 0) { throw x; } } catch (unsigned int e) {
cout << "Caught an exception: " << e; }
The throw statement should not throw integers
The catch block is catching the wrong type of exception
There is no error
The if condition is incorrect
Q150
Q150 What are regular expressions used for in C++?
To optimize algorithms
To create complex data structures
To search, edit, or manipulate text
To manage file input/output operations


