Question: A stack is implemented using a dynamic array, and the realloc function is used to resize the array when the stack grows or shrinks. Which
A stack is implemented using a dynamic array, and the realloc function is used to resize the array when the stack grows or shrinks. Which of the following statements is TRUE about the function in the context of stack implementation?
When the stack grows, realloc always returns a new block of memory with the increased size, and the old block is deallocated.
When the stack grows, realloc may return a new block of memory with the increased size or it may return the same block of memory, depending on the availability of contiguous memory.
realloc is not used in stack implementation, as it is only used for heap allocation.
When the stack grows, realloc always returns the same block of memory, and the size is increased in place.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
