C Queue Operations

Intermediate
6 min read
Updated: Nov 2026
1 example

The Core Operations

The standard queue operations are enqueue, dequeue, front (peek), size, and is_empty. With head and tail indexes, tail is the next free slot, so size = tail - head. All operations are O(1).

Remember
enqueue: q->data[q->tail++] = v;
dequeue: v = q->data[q->head++];
size   : q->tail - q->head
empty  : q->head == q->tail

Cheat Sheet

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

TopicDetail
enqueueO(1)
dequeueO(1)
frontO(1)
sizetail - head

C Examples

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

Example 1 — Queue operations on a struct

Enqueue three values and dequeue one.

C
#include <stdio.h>

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

static void enqueue(struct Queue *q, int v) { q->data[q->tail++] = v; }
static int  dequeue(struct Queue *q)        { return q->data[q->head++]; }
static int  front(const struct Queue *q)    { return q->data[q->head]; }
static int  size(const struct Queue *q)     { return q->tail - q->head; }

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

    enqueue(&q, 5); enqueue(&q, 6); enqueue(&q, 7);
    printf("front=%d\n", front(&q));
    printf("dequeued %d\n", dequeue(&q));
    printf("size=%d\n", size(&q));
    printf("front=%d\n", front(&q));
    return 0;
}

How It Works

  1. Enqueue stores at tail; dequeue reads at head.
  2. After one dequeue, the size is 3 - 1 = 2.
  3. The new front is the second value, 6.

Edge Cases & Pitfalls

Check these before relying on Queue Operations in real programs.

empty

No emptiness check

Dequeue on an empty queue reads stale data.

full

No capacity check

This demo omits it for brevity. Add if (q->tail == 8) in real code.

Key Takeaways

  • All O(1).
  • Size is tail minus head.
  • Check empty/full.

One line: The standard queue operations are enqueue, dequeue, front (peek), size, and is_empty.

Frequently Asked Questions

Enqueue, dequeue, front (peek), is-empty, and size.
O(1) for array-based (circular) and linked-list queues with a tail pointer.
Continue with "Queue Array Implementation in C" next. See how a linear array queue wastes space and why that matters. The C Queues hub lists every topic in order.

Next: Queue Array Implementation in C

See how a linear array queue wastes space and why that matters.

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.

9 people found this page helpful