Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Stacks (LIFO) Using Arra | C Programming Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. C Programming Fundamentals

Lesson 31 of 50

·c

Stacks (LIFO) Using Arrays

10 mins

Course progress62%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • `top` index points to the most recent element.
  • Check for overflow (`top == MAX-1`) before `push`.
  • Check for underflow (`top == -1`) before `pop`.
  • Useful for expression evaluation, backtracking, recursion simulation.

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; }
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from C Programming FundamentalsBrowse activities
Previous lessonDynamic Data Structures – Doubly Linked ListContinue to lesson 32Queues (FIFO) Using Circular BuffersBack to C Programming Fundamentals curriculum