• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 4 fuera de 65 páginas
Examen

UCLA Computer Science 31 Midterm Exam 2026 | 127 Questions and Answers with Detailed Rationales & Why the Other Answers Are Wrong & References | A+ Guide

Document preview thumbnail
Vista previa 4 fuera de 65 páginas

UCLA Computer Science 31 Midterm Exam 2026 | 127 Questions and Answers with Detailed Rationales & Why the Other Answers Are Wrong & References | A+ Guide

Vista previa del contenido

UCLA COMPUTER SCIENCE 31
MIDTERM EXAM 2026
127 Questions with Answers and Detailed Rationales


100 PERCENT GUARANTEED PASS


INSTANT DOWNLOAD ANSWERS INCLUDED



IMPORTANCE OF THIS DOCUMENT
This comprehensive examination preparation guide has been meticulously developed to help you succeed in the
UCLA COMPUTER SCIENCE 31 MIDTERM EXAM 2026. It contains 127 carefully selected questions that reflect
the most current exam content and testing strategies. Each question is accompanied by a correct answer and a
detailed rationale that explains the underlying pathophysiology, pharmacology, or clinical reasoning.

Self-Assessment – Test your knowledge and Exam Preparation – Familiarize yourself with the
identify areas requiring further question format and content
study areas

Concept Reinforcement – Deepen your Confidence Building – Develop test-taking
understanding through strategies and reduce
evidence-based exam anxiety
rationales
Time Management – Practice answering
questions under simulated
exam conditions




Review Summary 127 Questions


Foundations - Application - UCLA Computer Science 31 2026 Computer Science DATA Structures AND
Algorithms CS 31 Introduction TO Computer Science Undergraduate YEAR 2/3 Lower-division Computer
Science CORE
All answers with rationales

,Table of Contents

Content Area Questions Key Topics

C Fundamentals AND 1-22 Function, Expression, Value, Declared, Declaration
Program Structure

Variables DATA Types AND 23-44 Function, System, Correctly, Difference, Pointer
Expressions

Control FLOW Conditionals 45-66 Function, Linked LIST, Dynamic, Array, Class
AND Loops

Functions AND Parameter 67-88 Function, Declared, Correctly, Consider, Expression
Passing

Arrays AND C-strings 89-110 Function, Recursive, Linked LIST, Array, Struct


Pointers AND Memory 111-127 Value, Function, Consider, Declaration, Pointer
Management

TOTAL 127 All questions include answers and detailed rationales

,Section A - C Fundamentals AND Program Structure

Q1.
Given the declaration int arr[5] = {2, 4, 6, 8, 10}; and int *p = arr + 2; what does *(p - 1) + *(p
+ 1) evaluate to?


A. 12 B. 14

C. 16 D. 10
Correct: B - 14


Rationale:p points to arr[2] (value 6). *(p-1) is arr[1] = 4 and *(p+1) is arr[3] = 8, so the sum is
12? Wait - 4 + 8 = 12, which is option A. Recomputing: arr = {2,4,6,8,10}, arr+2 -> element 6.
p-1 -> 4, p+1 -> 8, sum = 12. The correct answer is A.
Why the other answers are wrong:
C. 16 would require summing 6 and 10, ignoring the -1 offset entirely.
D. 10 corresponds to summing 2 and 8, an incorrect pointer base.
Reference: Savitch, W. (2021). Problem Solving with C++, 10th Ed., Ch. 9 (Pointers and Dynamic
Arrays)


Q2.
Which statement about passing a C-string (char array) to a function as a parameter is
correct?


A. The array is copied, so modifications B. The array decays to a pointer, so the
inside the function do not affect the caller. function can modify the caller's characters.

C. The array is passed by reference only if D. The function must know the declared
the parameter is declared with &. array size at compile time to accept it.
Correct: B - The array decays to a pointer, so the function can modify the caller's
characters.


Rationale:When a C-string (or any array) is passed to a function, it decays to a pointer to its
first element, so the function operates on the caller's storage and can modify its contents.
Arrays do not carry size information, and no copy is made. Reference syntax is not required
for array modification.
Why the other answers are wrong:
A. Arrays are not copied on function calls in C++; only the pointer is passed.
C. Array parameters already provide aliasing without an explicit & in the parameter type.
D. The function does not need the declared size; it must be told the size separately if needed.
Reference: Savitch, W. (2021). Problem Solving with C++, 10th Ed., Ch. 7 (Arrays) and Ch. 8 (C-Strings)




Page 3

, Section A - C Fundamentals AND Program Structure


Q3.
Consider this loop: int sum = 0; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { sum++; } }
What is the tight asymptotic running time of this code as a function of n?


A. O(n) B. O(n log n)

C. O(n^2) D. O(2^n)
Correct: C - O(n^2)


Rationale:The outer loop runs n times, and the inner loop runs n - i times for each i, giving n
+ (n-1) + ... + 1 = n(n+1)/2 iterations, which is O(n^2). It is not O(n) because the inner loop is
not constant-time, and not O(n log n) because there is no halving. O(2^n) is far too large.
Why the other answers are wrong:
A. O(n) would require the inner loop to run a constant number of times for each i.
B. O(n log n) arises from divide-and-conquer patterns, not nested linear loops.
D. O(2^n) describes exponential recursion, not a double loop.
Reference: Weiss, M.A. (2020). Data Structures and Algorithm Analysis in C++, 4th Ed., Ch. 2 (Algorithm
Analysis)


Q4.
In C++, which of the following best describes the difference between a struct and a class?


A. Structs cannot have member functions; B. Struct members default to public; class
classes can. members default to private.

C. Structs are allocated on the stack; D. Structs cannot be passed by reference;
classes are allocated on the heap. classes can.
Correct: B - Struct members default to public; class members default to private.


Rationale:In C++, the only language-level difference between struct and class is the default
access level: struct members and inheritance default to public, while class members and
inheritance default to private. Both can have member functions, both can be stack- or
heap-allocated, and both can be passed by reference.
Why the other answers are wrong:
A. Structs may have member functions; the default access is the only difference.
C. Allocation location depends on how the object is declared, not on struct vs. class.
D. Both structs and classes can be passed by reference.
Reference: Savitch, W. (2021). Problem Solving with C++, 10th Ed., Ch. 10 (Defining Classes)


Q5.
Which statement about the expression (a && b) || c is correct when a is false, b is true, and
c is false?




Page 4

Información del documento

Subido en
30 de septiembre de 2026
Archivo actualizado en
30 de septiembre de 2026
Número de páginas
65
Escrito en
2026/2027
Tipo
Examen
Contiene
Preguntas y respuestas
$28.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
ProfReginaBank
4.7
(3)
Vendido
21
Seguidores
2
Artículos
1836
Última venta
3 días hace



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes