







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








CS 142 Final Exam – Practice Document
Complete Study Guide with Answers & Rationale 2026/2027 Edition Instructions: This document contains 50 representative exam questions covering pointers, memory management, recursion, Big-O, classes, inheritance, polymorphism, STL, data structures, and RAII. Each question is followed by the answer and a rationale explaining why it is correct. Section I: Multiple Choice (30 questions)
Rationale: Without a virtual destructor, deleting a derived object via a base pointer causes undefined behavior (only base destructor runs). Virtual ensures the correct destructor chain.
D. Undefined behavior Answer: B Rationale: ref is a reference to x; assigning to ref modifies x directly.
D. The hash function is perfect Answer: B Rationale: Collisions are inevitable; they are handled by chaining or open addressing.
D. char Answer: B Rationale: uniqueptr automatically deletes the managed object when it goes out of scope.
Rationale: Stack overflow occurs when the call stack exceeds its limit, often from infinite recursion. Section III: Short Answer (5 questions)
Copy void swap(int* a, int* b) { int temp = *a; *a = *b; *b = temp; } Rationale: Pointers allow modification of original variables.