🔹 Introduction
In computer science, a Stack is one of the most fundamental data structures. It is widely used in programming for tasks such as function calls, expression evaluation, memory management, and undo operations in applications.
Understanding stacks is essential for students preparing for exams like UGC NET, as well as for real-world programming.
🔹 Definition
A Stack is a linear data structure that follows the LIFO (Last In, First Out) principle.
This means that the element inserted last is the first one to be removed.
👉 Real-life example:
Think of a stack of books. You can only remove the top book first.
🔹 Key Operations in Stack
A stack supports the following basic operations:
- Push – Adds an element to the top of the stack
- Pop – Removes the top element from the stack
- Peek (Top) – Returns the top element without removing it
- isEmpty – Checks whether the stack is empty
🔹 Representation of Stack
Top → 30
20
10
- If we perform
push(40)→ Top becomes 40 - If we perform
pop()→ 30 is removed
🔹 Implementation of Stack (C Language)
#include <stdio.h>
#define MAX 5
int stack[MAX];
int top = -1;
void push(int value) {
if (top == MAX - 1) {
printf("Stack Overflow\n");
} else {
top++;
stack[top] = value;
}
}
void pop() {
if (top == -1) {
printf("Stack Underflow\n");
} else {
top--;
}
}
void display() {
for (int i = top; i >= 0; i--) {
printf("%d\n", stack[i]);
}
}
int main() {
push(10);
push(20);
push(30);
display();
pop();
display();
return 0;
}

🔹 Applications of Stack
Stacks are used in many real-world scenarios:
- Function call handling (call stack)
- Expression evaluation (infix to postfix)
- Undo/Redo operations in editors
- Syntax parsing in compilers
- Backtracking algorithms
🔹 Advantages
- Simple and easy to implement
- Efficient memory usage
- Useful in recursion and expression evaluation
🔹 Disadvantages
- Limited size (in array implementation)
- No direct access to middle elements
- Can cause overflow/underflow errors
🔹 Conclusion
A stack is a powerful yet simple data structure that plays a critical role in programming. Its LIFO behavior makes it ideal for many computational tasks, especially those involving recursion and memory management.
A strong understanding of stacks builds a solid foundation for learning advanced data structures and algorithms.