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

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. C Programming Fundamentals

Lesson 32 of 50 · c

Queues (FIFO) Using Circular Buffers

Duration: 12 mins

A queue follows first‑in‑first‑out. A circular buffer efficiently implements a fixed‑size queue without moving elements.

#define CAP 5
int q[CAP];
int front = 0, rear = 0, size = 0;

int enqueue(int x) {
    if (size == CAP) return -1; // full
    q[rear] = x;
    rear = (rear + 1) % CAP;
    ++size;
    return 0;
}

int dequeue(int *out) {
    if (size == 0) return -1; // empty
    *out = q[front];
    front = (front + 1) % CAP;
    --size;
    return 0;
}
Previous: Stacks (LIFO) Using ArraysNext: Binary Trees – Basic Operations