# Difference between Stack and Array

**Stack:**

A stack is a linear data structure in which elements can be inserted and deleted only from one side of the list, called the *top*. A stack follows the *LIFO* (Last In First Out) principle, i.e., the element inserted at the last is the first element to come out. The insertion of an element into stack is called *push* operation, and deletion of an element from the stack is called *pop* operation. In stack we always keep track of the last element present in the list with a pointer called *top*.

The diagrammatic representation of stack is given below:

**Array:**

An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. This makes it easier to calculate the position of each element by simply adding an offset to a base value, i.e., the memory location of the first element of the array (generally denoted by the name of the array).

The diagrammatic representation of Array is given below:

**Difference between Stack and Array Data Structures:**

Stacks | Array |
---|---|

Stacks are based on the LIFO principle, i.e., the element inserted at the last, is the first element to come out of the list. | In the array the elements belong to indexes, i.e., if you want to get into the fourth element you have to write the variable name with its index or location within the square bracket eg arr[4] |

Insertion and deletion in stacks takes place only from one end of the list called the top. | Insertion and deletion in array can be done at any index in the array. |

Stack has a dynamic size. | Array has a fixed size. |

Stack can contain elements of different data type. | Array contains elements of same data type. |

We can do only linear search | We can do both linear and Binary search |

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

## Recommended Posts:

- Stack Permutations (Check if an array is stack permutation of other)
- Difference between Stack and Queue Data Structures
- Check if an array is stack sortable
- Growable array based stack
- Range Sum and Update in Array : Segment Tree using Stack
- Count the number of pop operations on stack to get each element of the array
- Difference between Static allocation and Stack allocation
- Infix to Postfix using different Precedence Values for In-Stack and Out-Stack
- Find maximum in stack in O(1) without using additional stack
- Count elements in first Array with absolute difference greater than K with an element in second Array
- Sort a stack using a temporary stack
- Stack | Set 3 (Reverse a string using stack)
- Difference between pointer to an array and array of pointers
- Sum of elements in an array whose difference with the mean of another array is less than k
- Difference between Programmable Logic Array and Programming Array Logic

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.