COP 3502C Programming Fundamentals I
Finals Mock Exam Review
(Questions & Solutions)
2025
©2025
, Question 1
Consider the recursive function below which is intended to compute the
factorial of a number:
```c
int factorial(int n) {
if (n <= 1)
return 1;
else
return n factorial(n - 1);
}
```
What is the primary purpose of the condition `if (n <= 1)` in this
function?
A) To prevent infinite recursion by providing a terminating condition
B) To optimize multiplication for large numbers
C) To handle negative inputs gracefully
D) To initialize values before recursive calls
ANS: A) To prevent infinite recursion by providing a terminating
condition.
Rationale: The condition `if (n <= 1)` serves as the base case which
stops further recursive calls. This termination prevents the function from
calling itself indefinitely.
---
Question 2
Tail recursion is often discussed as a technique to optimize recursive
function calls.
©2025
, Which option best defines tail recursion?
A) The recursive call is the final operation in the function
B) The recursive call is made at the start of the function
C) Recursion happens in multiple steps before the final computation
D) The function calls itself in the middle of an arithmetic operation
ANS: A) The recursive call is the final operation in the function.
Rationale: Tail recursion occurs when the recursive call is the last action
performed. This pattern enables compilers to optimize the recursion and
reuse the current function’s stack frame.
---
Question 3
When using recursion, one of the main disadvantages is:
A) Always faster execution compared to loops
B) Increased risk of stack overflow
C) Elimination of the need for a base case
D) Lower memory usage than iterative solutions
ANS: B) Increased risk of stack overflow.
Rationale: Each recursive invocation adds a layer to the call stack. In
deep recursions, this can lead to exceeding the available stack memory,
resulting in a stack overflow.
---
Question 4
In C programming, the relationship between arrays and pointers is often
discussed. Which of the following statements correctly describes this
©2025
, relationship?
A) Arrays and pointers are completely interchangeable in all contexts
B) An array name represents the address of its first element, but it is not
a pointer
C) Pointers always require explicit dynamic memory allocation while
arrays do not
D) Pointer arithmetic on an array name always yields individual element
values
ANS: B) An array name represents the address of its first element, but
it is not a pointer.
Rationale: While an array name can decay to a pointer to its first
element in many contexts, it is not the same as a pointer since it has
fixed size and stored in a non-modifiable location.
---
Question 5
Exception handling is an important concept in robust software design.
Which of the following best describes its primary purpose?
A) To bypass errors without addressing them
B) To provide a framework for handling runtime errors gracefully
C) To remove the need for error checking entirely
D) To accelerate the compilation process
ANS: B) To provide a framework for handling runtime errors gracefully.
Rationale: Exception handling mechanisms allow a program to detect
runtime errors and manage them in an orderly fashion, ensuring that the
program can continue or terminate gracefully.
---
©2025
Finals Mock Exam Review
(Questions & Solutions)
2025
©2025
, Question 1
Consider the recursive function below which is intended to compute the
factorial of a number:
```c
int factorial(int n) {
if (n <= 1)
return 1;
else
return n factorial(n - 1);
}
```
What is the primary purpose of the condition `if (n <= 1)` in this
function?
A) To prevent infinite recursion by providing a terminating condition
B) To optimize multiplication for large numbers
C) To handle negative inputs gracefully
D) To initialize values before recursive calls
ANS: A) To prevent infinite recursion by providing a terminating
condition.
Rationale: The condition `if (n <= 1)` serves as the base case which
stops further recursive calls. This termination prevents the function from
calling itself indefinitely.
---
Question 2
Tail recursion is often discussed as a technique to optimize recursive
function calls.
©2025
, Which option best defines tail recursion?
A) The recursive call is the final operation in the function
B) The recursive call is made at the start of the function
C) Recursion happens in multiple steps before the final computation
D) The function calls itself in the middle of an arithmetic operation
ANS: A) The recursive call is the final operation in the function.
Rationale: Tail recursion occurs when the recursive call is the last action
performed. This pattern enables compilers to optimize the recursion and
reuse the current function’s stack frame.
---
Question 3
When using recursion, one of the main disadvantages is:
A) Always faster execution compared to loops
B) Increased risk of stack overflow
C) Elimination of the need for a base case
D) Lower memory usage than iterative solutions
ANS: B) Increased risk of stack overflow.
Rationale: Each recursive invocation adds a layer to the call stack. In
deep recursions, this can lead to exceeding the available stack memory,
resulting in a stack overflow.
---
Question 4
In C programming, the relationship between arrays and pointers is often
discussed. Which of the following statements correctly describes this
©2025
, relationship?
A) Arrays and pointers are completely interchangeable in all contexts
B) An array name represents the address of its first element, but it is not
a pointer
C) Pointers always require explicit dynamic memory allocation while
arrays do not
D) Pointer arithmetic on an array name always yields individual element
values
ANS: B) An array name represents the address of its first element, but
it is not a pointer.
Rationale: While an array name can decay to a pointer to its first
element in many contexts, it is not the same as a pointer since it has
fixed size and stored in a non-modifiable location.
---
Question 5
Exception handling is an important concept in robust software design.
Which of the following best describes its primary purpose?
A) To bypass errors without addressing them
B) To provide a framework for handling runtime errors gracefully
C) To remove the need for error checking entirely
D) To accelerate the compilation process
ANS: B) To provide a framework for handling runtime errors gracefully.
Rationale: Exception handling mechanisms allow a program to detect
runtime errors and manage them in an orderly fashion, ensuring that the
program can continue or terminate gracefully.
---
©2025