CS 61C Quiz - Week 2-1-1: Monday

Questions 1 and 2 refer to the code described in section 8.7 of K&R.

Current time: Fri Aug 22 19:41:48 2025

Deadline: Mon Jun 28 11:00:00 2004

Name:
SID:
Login:cs61c-

Question 1:

1.  Which of the following statements are true about a successful call
to malloc, that is, a call that returns a non-NULL pointer?
None may be true, or more than one statement may be true.
Briefly explain your answer.

a. A successful call to malloc will always reduce the number of free blocks.
b. A successful call to malloc may leave the number of free blocks unchanged.
c. A successful call to malloc may increase the number of free blocks.

Question 2:

2.  Which of the following statements are true about a call to free?
None may be true, or more than one statement may be true.
Briefly explain your
answer.

a. A call to free always increases the number of free blocks.
b. A call to free may leave the number of free blocks unchanged.
c. A call to free may reduce the number of free blocks by 1, but never by more than 1.
d. A call to free may reduce the number of free blocks by 2 or more.

Question 3:

3.  What is the Java equivalent to malloc in C? What is the Java
equivalent to free in C? Why can't someone build an automatic memory
allocation / deallocation system for C like those available for
Java?

Question 4:

Consider a structure of the form
 ___________      ___________
|   |   |   |    |  /|   |   |
| o |   | o----->| / |   | o |
|_|_|___|___|    |/__|___|_|_|
  |                        |
 _v_________      _________v_
|  /|   |   |    |  /|   |  /|
| / |   | o----->| / |   | / |
|/__|___|___|    |/__|___|/__|
Can this structure be reclaimed using the reference count method? Can it be reclaimed using the mark and sweep method? Briefly explain your answers.

Question 5:

5. What did you find difficult or confusing about the reading? If
  nothing was difficult or confusing, tell us what you found most
  interesting. Please be as specific as possible.

Send a confirmation email to my class account.