BillHung.Net


powered by FreeFind     sms

Quiz 03

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.

a. False. A successful call to malloc increase the number of free blocks.

b. False. A successful call to malloc increase the number of free blocks. (Same argument as a.)

c. True. A successful call to malloc increase the number of free blocks. (Same again.)

Question 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.

a. True. If the call to free is successful, the number of free blocks is reduced.

b. True. If the call to free is not successful.

c. False. If the block to free is an array, more than 1 blocks are free,so this argument is not always true.

d. True. If the block to free is an array or things like that.
Question 3:
What did you find difficult or confusing about the reading? If
nothing was difficult or confusing, tell us what you found most
interesting. In either case, please be as specific as possible.

I think the "free block" refers to the allocated block of memory for program to use.

So a free call reduce a "free block", which is reduce the block of memory for programs to use.