Stack

In computing, a stack is a data structure used to store a collection of objects. Individual items can be added and stored in a stack using a push operation. Objects can be retrieved using a pop operation, which removes an item from the stack.

When an object is added to a stack, it is placed on the top of all previously entered items. When an item is removed, it can either be removed from the top or bottom of the stack. A stack in which items are removed the top is considered a "LIFO" (Last In, First Out) stack. You can picture a LIFO stack as a deck of cards where you lay individual cards on the deck, then draw cards from the top. In a "FIFO" (First In, First Out) stack, items are removed the bottom. You can picture a FIFO stack as a row in a vending machine where items are dispensed in the order they were placed in the machine.

Stacks have several applications in commuter programming. LIFO stacks, for example, can be used to retrieve recently used objects, from a cache. FIFO stacks may be used to ensure data is retrieved in the order it was entered, which may be used for processing data in a queue.

While stacks are commonly used by software programmers, you will typically not notice them while using a program. This is because the creation of stacks and push and pop operations are performed in the background while an application is running and are not visible to the user. However, if a stack runs out of memory, it will cause a "stack overflow." If not handled correctly by the program, a stack overflow may generate an error message or cause the program to crash.

NOTE: The term "stack" may also refer to a protocol stack, which consists of multiple network protocols that work together. Each protocol is categorized into one of seven different layers defined in the OSI model.

Updated July 23, 2014 by Per C.

quizTest Your Knowledge

Endianness refers to how data is ____?

A
Stored
0%
B
Deleted
0%
C
Transmitted
0%
D
Transformed
0%
Correct! Incorrect!     View the Endianness definition.
More Quizzes →

The Tech Terms Computer Dictionary

The definition of Stack on this page is an original definition written by the TechTerms.com team. If you would like to reference this page or cite this definition, please use the green citation links above.

The goal of TechTerms.com is to explain computer terminology in a way that is easy to understand. We strive for simplicity and accuracy with every definition we publish. If you have feedback about this definition or would like to suggest a new technical term, please contact us.

Sign up for the free TechTerms Newsletter

How often would you like to receive an email?

You can unsubscribe or change your frequency setting at any time using the links available in each email.

Questions? Please contact us.