Queue Array Implementation in C

Intermediate
6 min read
Updated: Nov 2026
1 example

Queue Backed by an Array

A linear array queue advances head on dequeue and tail on enqueue. It is simple but suffers from false fullness: after a few dequeues, the front slots are unused, yet tail is at the end of the array, so new items are rejected. Solutions: shift elements (O(n)) or use a circular queue.

Remember
#define CAP 3
struct Queue { int data[CAP]; int head, tail; };
if (q->tail == CAP) { /* "full" even if head > 0 */ }

Cheat Sheet

Keep these facts handy while you work with Queue Array Implementation in C in C.

TopicDetail
Full testtail == CAP
Wasted slotsIndexes before head
Fix 1Shift left O(n)
Fix 2Circular queue

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Queue Linked List Implementation in C.

Example 1 — The false-full problem

Capacity 3: enqueue 3, dequeue 1, enqueue again.

C
#include <stdio.h>
#define CAP 3

struct Queue { int data[CAP]; int head, tail; };

static int enqueue(struct Queue *q, int v) {
    if (q->tail == CAP) return 0;
    q->data[q->tail++] = v;
    return 1;
}

int main(void) {
    struct Queue q = {{0}, 0, 0};

    for (int i = 1; i <= 3; i++)
        printf("enqueue %d: %s\n", i, enqueue(&q, i) ? "ok" : "full");

    printf("dequeued %d\n", q.data[q.head++]);
    printf("enqueue 4: %s\n", enqueue(&q, 4) ? "ok" : "full");
    printf("size=%d\n", q.tail - q.head);
    return 0;
}

How It Works

  1. After dequeuing, slot 0 is free but tail is still 3.
  2. The queue reports full while holding only 2 items.
  3. A circular queue would accept 4.

Edge Cases & Pitfalls

Check these before relying on Queue Array Implementation in C in real programs.

false

False full

Linear array queues waste the slots before head.

reset

Resetting only when empty

You can reset head and tail to 0 when the queue empties, but not otherwise.

Key Takeaways

  • Simple but wasteful.
  • False full condition.
  • Use circular for production.

One line: A linear array queue advances head on dequeue and tail on enqueue.

Frequently Asked Questions

Dequeued slots at the front are never reused because tail only moves forward.
Use a circular queue with modulo arithmetic so indexes wrap around.
Continue with "Queue Linked List Implementation in C" next. Enqueue at the tail and dequeue at the head of a linked list. The C Queues hub lists every topic in order.

Next: Queue Linked List Implementation in C

Enqueue at the tail and dequeue at the head of a linked list.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful