Lesson 31 of 50 · c
Stacks (LIFO) Using Arrays
Duration: 10 mins
A stack follows last‑in‑first‑out order. Implemented easily with a fixed‑size array and an integer index.
#define MAX 100
int stack[MAX];
int top = -1; // empty stack
void push(int x) { if (top < MAX-1) stack[++top] = x; }
int pop(void) { if (top >= 0) return stack[top--]; return -1; }