为什么不能使用realloc函数来调整动态数组的堆栈?

时间:2022-07-25 18:51:09

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.

这本书告诉我,我应该声明一个新的更大的数组(malloc)并将数据从旧数组复制到新数组以调整堆栈大小。

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

但为什么我不能使用realloc来调整堆栈长度的大小?

1 个解决方案

#1


1  

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.

没有人阻止你使用realloc。此外,realloc是优选的。在没有查看材料的上下文的情况下,我无法分辨作者的意图为什么他要使用malloc。

#1


1  

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.

没有人阻止你使用realloc。此外,realloc是优选的。在没有查看材料的上下文的情况下,我无法分辨作者的意图为什么他要使用malloc。