Skip to main content

Object Oriented Programming MCQs with Answers

Practice important Object Oriented Programming MCQs with answers and explanations.

Chapter: 42
Q641:
Fill in the blank: To traverse a container in both directions, you would use a ________ Iterator.
A. Bidirectional
B. Forward
C. Random-access
D. Input
Correct Answer: A
Chapter: 42
Q642:
Which iterator category is suitable for algorithms requiring multiple passes over a container?
A. Random-access Iterators
B. Forward Iterators
C. Bidirectional Iterators
D. Input Iterators
Correct Answer: C
Chapter: 42
Q643:
In the given example, `std::copy(begin, end, output);` demonstrates the use of which algorithm?
A. Mutating-Sequence Algorithm
B. Non-Mutating-Sequence Algorithm
C. Numeric Algorithm
D. No algorithm
Correct Answer: A
Chapter: 42
Q644:
The `std::fill` algorithm is used to ________.
A. Generate values in a container
B. Copy values from one container to another
C. Replace all values in a container with a given value
D. Find the maximum value in a container
Correct Answer: C
Chapter: 42
Q645:
In the example with `IntSet`, why does the code `cout << it[i] << ", ";` produce an error?
A. `IntSet` does not support random-access Iterators
B. `IntSet` does not support bidirectional Iterators
C. `IntSet` does not support input Iterators
D. `IntSet` does not support output Iterators
Correct Answer: A
Chapter: 42
Q646:
Fill in the blank: The `std::istream_iterator` is used for ________.
A. Reading input from a stream
B. Writing output to a stream
C. Incrementing values in a container
D. Assigning new values to a container
Correct Answer: A
Chapter: 42
Q647:
Which algorithm is used to fill a container with a specified value?
A. copy
B. fill
C. generate
D. partition
Correct Answer: B
Chapter: 42
Q648:
What is the result of using `p + i` with a Random-access Iterator?
A. It returns an iterator pointing at `p + i`
B. It returns a reference of the element at `p + i`
C. It increments the iterator by `i` positions
D. It returns true if `p` is before `i`
Correct Answer: A
Chapter: 42
Q649:
Fill in the blank: The example `std::copy(begin, end, output);` outputs elements using ________.
A. `std::ostream_iterator`
B. `std::istream_iterator`
C. `std::vector`
D. `std::list`
Correct Answer: A
Chapter: 42
Q650:
Which iterator type is suitable for traversing `std::set` and `std::map` containers?
A. Random-access Iterators
B. Input Iterators
C. Output Iterators
D. Bidirectional Iterators
Correct Answer: D
Chapter: 43
Q651:
What is an example of abnormal termination in error handling?
A. Returning an error code
B. Graceful exit
C. Immediate program termination
D. Exception handling
Correct Answer: C
Chapter: 43
Q652:
What does graceful termination in error handling involve?
A. Immediate exit without cleanup
B. Exiting after cleanup
C. Ignoring errors
D. Crashing the system
Correct Answer: B
Chapter: 43
Q653:
What happens when a program uses return with an illegal value for error handling?
A. Program crashes immediately
B. Program exits gracefully
C. Program continues with modified data
D. Program displays an error message
Correct Answer: C
Chapter: 43
Q654:
What is the output when a denominator is zero in a program with graceful termination?
A. Program terminates abnormally
B. Clean exit with an error message
C. The program continues as normal
D. Data loss occurs
Correct Answer: B
Chapter: 43
Q655:
In exception handling, what is the purpose of the try block?
A. To execute code that might cause an exception
B. To catch exceptions
C. To throw exceptions
D. To handle program crashes
Correct Answer: A
Chapter: 43
Q656:
How is an exception thrown in C++?
A. Using the throw keyword
B. Using the catch keyword
C. Using the return statement
D. Using the exit function
Correct Answer: A
Chapter: 43
Q657:
What is the role of the catch block in exception handling?
A. To execute code that might cause an exception
B. To catch exceptions thrown in the try block
C. To terminate the program
D. To initialize variables
Correct Answer: B
Chapter: 43
Q658:
What is an example of an object used to represent an exception in C++?
A. DivideByZero class
B. ErrorHandler class
C. ErrorCode class
D. Exception class
Correct Answer: A
Chapter: 43
Q659:
What happens if a function returns false for error handling?
A. The function is retried
B. The program crashes
C. The error is handled gracefully
D. The error message is displayed
Correct Answer: C
Chapter: 43
Q660:
Which error handling technique involves separating error handling code from main logic?
A. Graceful termination
B. Abnormal termination
C. Exception handling
D. Returning illegal values
Correct Answer: C

Test Your Knowledge

Take a timed quiz on Object Oriented Programming

🚀 Start Quiz Now