Both the stack and the heap are parts of memory available to your code to use at runtime, but they are structured in different ways. The stack stores values in the order it gets them and removes the values in the opposite order. This is referred to as last in, first out. Think of a stack of plates: when you add more plates, you put them on top of the pile, and when you need a plate, you take one off the top. Adding or removing plates from the middle or bottom wouldn’t work as well! Adding data is called pushing onto the stack, and removing data is called popping off the stack. All data stored on the stack must have a known, fixed size. Data with an unknown size at compile time or a size that might change must be stored on the heap instead. 栈和堆都是代码在运行时可使用的内存部分,但它们的结构不同。栈按照获取值的顺序存储值,并以相反的顺序移除值。这被称为后进先出。想象一摞盘子:当你添加更多盘子时,你把它们放在这摞盘子的顶部,当你需要一个盘子时,你从顶部取一个。从中间或底部添加或移除盘子就不那么方便了!添加数据叫做进栈,移除数据叫做出栈。存储在栈上的所有数据都必须有一个已知的固定大小。在编译时大小未知或大小可能变化的数据必须存储在堆上。