简体   繁体   English

数组如何存储在堆栈中?

[英]How are arrays stored on the stack?

I know how arrays stored on the heap.我知道数组是如何存储在堆上的。 But how are arrays stored on the stack?但是数组是如何存储在栈上的呢? Is the complete array pushed to the stack?是否将完整的数组压入堆栈?

Arrays are stored the same no matter where they are.数组无论在何处都以相同的方式存储。 It doesn't matter if they are declared as local variables, global variables, or allocated dynamically off the heap.它们是被声明为局部变量、全局变量还是在堆外动态分配都没有关系。 The only thing that differs is where they are stored.唯一令不同的是他们的存储位置

Yes, the whole array is pushed on stack.是的,整个数组被压入堆栈。

See the following answer on how variables are allocated on the stack:请参阅以下有关如何在堆栈上分配变量的答案:

https://stackoverflow.com/a/18479996/1814023 https://stackoverflow.com/a/18479996/1814023

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM