devxlogo

Explaining Stacks

Explaining Stacks

Question:
Could you please give me a simple explanation to what stacks are? How do they work and what are their related features?

Answer:
Stacks are temporary resting places for variables or code in memory. They work like those dish dispensers in large cafeterias: when you put (i.e., “push”) something on the stack, it sits on the top until something else gets put on top if it. If you want to get something off (i.e., “pop”) the stack, you have to remove everything that is ahead (on top) of it first, until you reach your item.

devx-admin

Share the Post: