Data structures in C programs are ways of organising and storing data so operations like insertion, deletion and traversal run efficiently. A circular queue in C is a fixed-size array where the last slot wraps to the first using modular arithmetic, reusing freed memory that a linear queue wastes. It runs enqueue and dequeue in O(1) time and is core to operating system scheduling and I/O buffering.
- Key Takeaway 1: A circular queue uses modular arithmetic to wrap
frontandrearpointers, so no slot goes to waste after a dequeue. - Key Takeaway 2: Both enqueue and dequeue run in O(1) time, making the circular queue one of the most efficient fixed-size queue implementations in data structures in C programs.
- Key Takeaway 3: Overflow happens when
(rear + 1) % SIZE == front, meaning every slot is occupied, not whenrearhits the last index. - Key Takeaway 4: Indian university syllabi for B.Tech CSE and BCA at SPPU, Anna University, VTU and Delhi University consistently include circular queues as a core data structures in C programs topic from the second semester onward.
- Key Takeaway 5: Practicing one complete circular queue program in C from scratch is enough to cement your understanding of pointer arithmetic and boundary conditions.
Why a Circular Queue Beats a Linear Queue
Picture a linear queue with 5 slots. You enqueue 5 elements, then dequeue 3. Slots 0, 1 and 2 are now empty, but rear is already at index 4. A linear queue sees those freed slots and says “full.” That is wasted memory, and in embedded systems or real-time applications it is a real problem.
A circular queue fixes this by treating the array as a ring. When rear reaches the last index, it wraps to index 0 if space is available there. The condition (rear + 1) % SIZE == front is the only true overflow signal. This is why data structures in C programs courses always teach circular queues after linear queues.
Linear vs Circular Queue: A Direct Comparison
| Feature | Linear Queue | Circular Queue |
|---|---|---|
| Memory reuse after dequeue | No | Yes |
| Overflow condition | rear == SIZE – 1 | (rear + 1) % SIZE == front |
| Enqueue time complexity | O(1) | O(1) |
| Dequeue time complexity | O(1) or O(n) with shift | O(1) |
| Typical use case | Simple task lists | CPU scheduling, I/O buffers |
| Wasted slots possible | Yes | No |
According to NPTEL’s Data Structures course (IIT Madras, 2023 edition), circular queues are among the top five data structure concepts tested in GATE CS, appearing in roughly 68% of GATE papers from 2015 to 2023 that included queue-related questions.
Complete Circular Queue Program in C: Enqueue and Dequeue
The full circular queue program in C below uses an integer array, two integer pointers (front and rear), and a size constant. Both are initialised to -1 to indicate an empty queue. Every insertion and deletion operation uses the modulo operator to keep the pointers within bounds. This is the standard pattern taught in data structures in C programs courses across Indian universities.
The Core Logic Before the Code
Enqueue (insertion): Check overflow first. If the queue is empty, set both front and rear to 0. Otherwise, move rear forward as rear = (rear + 1) % SIZE and insert the element.
Dequeue (deletion): Check underflow first. If front == rear, the queue has one element; reset both pointers to -1 after removing it. Otherwise, move front forward as front = (front + 1) % SIZE.
Full Working C Program
Copy this program, compile it with gcc circular_queue.c -o cq and run it directly. Every line is commented so you can follow the logic step by step. This is the exact style of circular queue program in C with output that examiners at SPPU, Anna University and VTU expect in practical exams.
#include <stdio.h>
#define SIZE 5
int queue[SIZE];
int front = -1, rear = -1;
int isFull() {
return (rear + 1) % SIZE == front;
}
int isEmpty() {
return front == -1;
}
void enqueue(int value) {
if (isFull()) {
printf("Queue Overflow! Cannot insert %d\n", value);
return;
}
if (isEmpty()) {
front = rear = 0;
} else {
rear = (rear + 1) % SIZE;
}
queue[rear] = value;
printf("Inserted: %d\n", value);
}
int dequeue() {
if (isEmpty()) {
printf("Queue Underflow! Nothing to remove.\n");
return -1;
}
int val = queue[front];
if (front == rear) {
front = rear = -1;
} else {
front = (front + 1) % SIZE;
}
printf("Removed: %d\n", val);
return val;
}
void display() {
if (isEmpty()) {
printf("Queue is empty.\n");
return;
}
int i = front;
printf("Queue: ");
while (1) {
printf("%d ", queue[i]);
if (i == rear) break;
i = (i + 1) % SIZE;
}
printf("\n");
}
int main() {
enqueue(10);
enqueue(20);
enqueue(30);
enqueue(40);
enqueue(50);
enqueue(60); /* Overflow test */
display();
dequeue();
dequeue();
enqueue(60); /* Slot reuse after deletion */
enqueue(70);
display();
return 0;
}
When you run this, you will see that after removing 10 and 20, the program successfully inserts 60 and 70 into the freed slots. A linear queue would have rejected both insertions because rear was already at index 4. That single difference is the entire point of the circular design and the reason data structures in C programs syllabi dedicate a full unit to it.
Enqueue and Dequeue Complexity at a Glance
- Time complexity, enqueue: O(1)
- Time complexity, dequeue: O(1)
- Space complexity: O(n), where n is the fixed array size
- No shifting required: Unlike a linear queue that shifts elements on dequeue, the circular version just moves a pointer
GeeksforGeeks (“Circular Queue Data Structure”, geeksforgeeks.org, updated 2024) reports that circular queue questions appear in technical interview rounds at companies like Infosys, TCS and Wipro specifically to test whether candidates understand modular arithmetic and boundary conditions in data structures in C programs, not just basic array manipulation.
Circular Queues in Indian University Exams and Placements
For students at Indian universities, circular queues are not optional. VTU’s B.Tech CSE syllabus (Scheme 2022, 3rd semester, subject code 22CS32) lists circular queues under Unit 2 of Data Structures and Applications. SPPU’s Second Year Computer Engineering syllabus and Anna University’s CS3301 Data Structures paper both include circular queue implementation as a mandatory practical. Mumbai University’s BCA and B.Sc IT programs cover it in the second semester.
In GATE CS, queue-based questions including circular queue overflow and underflow conditions have appeared in 2017, 2019, 2021 and 2023 papers. NPTEL’s “Data Structures and Algorithms” MOOC, which recorded over 2.1 lakh enrolments in its 2023 offering (NPTEL, nptel.ac.in, 2023), covers circular queues in Week 4 and is freely accessible to all Indian students.
For campus placements, TCS NQT and Infosys InfyTQ both include MCQ sections on data structures in C programs where circular queue overflow conditions, time complexity and pointer behaviour are regularly tested. Knowing the exact condition (rear + 1) % SIZE == front and being able to trace through a 5-slot example on paper is the minimum expected standard.
Where Circular Queues Show Up in Real Systems
This is not just academic. CPU scheduling algorithms like Round Robin use a circular queue to cycle through processes. Keyboard input buffers in operating systems store keystrokes in a circular queue so the system does not lose characters typed faster than the processor reads them.
Network routers use circular queues for packet buffering. The Linux kernel’s kfifo implementation is essentially a power-of-two circular buffer that handles concurrent producer-consumer scenarios without locks in many cases. According to the Linux Kernel documentation (kernel.org, 2024), kfifo is used across dozens of subsystems including audio drivers and USB stacks.
If you are aiming for a backend or systems role after graduation, understanding this structure gives you a concrete example to discuss in interviews. It shows you know why a design decision was made, not just what the code looks like. That kind of depth is exactly what separates candidates at entry-level tech jobs for fresh graduates.
Learning Path: Which Data Structures Come First?
If you are just starting out, do not jump straight to circular queues. Build your foundation in this order:
- Arrays — understand indexing, bounds and memory layout
- Linked Lists — singly, doubly, then circular
- Stacks — array-based and linked list-based
- Linear Queue — understand its limitations first
- Circular Queue — now the motivation is obvious
- Trees and Graphs — once you are confident with linear structures
This sequence mirrors the curriculum used by most Indian universities including SPPU, Anna University, VTU and Delhi University for their B.Tech and BCA programs. It is also the order recommended by NPTEL’s “Data Structures and Algorithms” MOOC, which had over 2.1 lakh enrolments in its 2023 offering.
Mastering data structures in C programs is consistently listed as one of the top skills every college student must learn before graduation if they want to compete for product and engineering roles.
How to Practice This Week
- Type the program above by hand, do not copy-paste; muscle memory matters for university practicals and GATE preparation
- Change
SIZEto 3 and trace through enqueue and dequeue operations on paper - Add a
peek()function that shows the front element without removing it - Rewrite the queue using a struct to hold
front,rearand the array together - Try implementing the same logic using a singly linked list instead of an array
- Solve at least three past GATE questions on circular queue overflow and underflow conditions
If you are deciding where to take your programming skills next, check out the best free online learning platforms for students in 2025 for structured C programming and data structures in C programs courses that will not cost you anything to start.
Once you are comfortable with data structures in C programs, the natural next step is understanding how these concepts feed into higher-paying specialisations. Our guide on top online courses for high-salary jobs in 2025 maps out exactly which certifications employers are paying a premium for right now.
Choosing a career path that actually uses these skills matters too. If you are still figuring out your direction, the guide on how to choose the right career path after graduation in 2026 gives a practical framework, and the breakdown of best career options in 2026 for students and professionals shows where demand is actually growing.
Knowledge of data structures in C programs opens doors in cybersecurity, AI engineering and backend development. If you want to build on this foundation with industry-recognised credentials, explore the data structures and programming courses at 3.0 University covering Cybersecurity, Ethical Hacking, AI, Blockchain and Web3. These are practical, project-based programs built for students, working professionals and career switchers who want skills that hold up in real interviews and real jobs.
Frequently Asked Questions
What is a circular queue in C?
A circular queue in C is an array-based queue where the last index wraps back to the first using modular arithmetic. It maintains two pointers, front and rear, initialised to -1. This structure allows all array slots to be reused after deletion, unlike a linear queue where dequeued positions stay permanently empty. It is a foundational topic in data structures in C programs for B.Tech CSE and BCA students.
How is a circular queue better than a linear queue?
A linear queue declares overflow when rear hits the last index, even if slots at the front are empty. A circular queue reuses those freed slots by wrapping rear around with (rear + 1) % SIZE. This means you get full utilisation of your allocated memory with no wasted positions and no element shifting needed.
How do you implement enqueue and dequeue in C?
For enqueue, check overflow with (rear + 1) % SIZE == front. If empty, set both pointers to 0. Otherwise, advance rear with modulo and insert. For dequeue, check underflow with front == -1. If only one element remains, reset both pointers to -1. Otherwise, advance front with modulo and return the removed value. This is the standard pattern in data structures in C programs practicals.
What causes overflow in a circular queue?
Overflow occurs when every slot in the array is occupied, specifically when (rear + 1) % SIZE == front. This is different from a linear queue where overflow triggers just because rear reached the last index. In a circular queue, one slot is always kept empty to distinguish between a full queue and an empty one.
Which data structures should a C beginner learn first?
Start with arrays, then move to linked lists, stacks and linear queues before tackling circular queues. This order builds the intuition you need: arrays teach indexing, linked lists teach pointers, stacks and linear queues teach the overflow problem. Once you see why a linear queue wastes memory, the circular queue design in data structures in C programs becomes immediately obvious.
Is circular queue asked in GATE CS?
Yes. Circular queue overflow conditions, pointer behaviour and time complexity have appeared in GATE CS papers in 2017, 2019, 2021 and 2023. According to NPTEL’s Data Structures course (IIT Madras, 2023 edition), circular queues appear in roughly 68% of GATE papers from 2015 to 2023 that included queue-related questions, making them a high-priority topic for GATE preparation.
If you want a broader view of what to learn alongside data structures in C programs to stay competitive, the 3.0 University guide on choosing the right career path after graduation is worth reading before you plan your next six months of study.
Last updated: June 2025. Reviewed by the 3University editorial team.