Search code examples
carraysstackadt

Why can't use realloc function to resize the stack which is of dynamic array?


The book tells me that I should declare a new, larger array (malloc) and copy the data from the old array to the new array to resize the stack.

But why can't I use realloc to adjust the size of the stack's length?


Solution

  • Nobody stops you from using realloc. Moreover realloc is preferable. Without looking at context of material, I can not tell the intention of author why does he want to use malloc.