Question:

Which one of the following is the correct way to increment the rear end of a circular queue represented as an array of size M?

Show Hint

The index must wrap from the last slot back to 0. Which formula gives 0 when rear equals M minus 1?
Updated On: Jul 2, 2026
  • rear = rear + 1
  • rear = 1
  • (rear + 1) % M
  • (rear % M) + 1
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: A circular queue uses an array of indices \(0\) to \(M-1\). When the rear reaches the last slot, it must wrap back to the start instead of running off the end.

Step 2: Plain \(rear = rear + 1\) keeps growing past \(M-1\) and causes an out-of-range index, so it is wrong for a circular queue.

Step 3: The wrap is achieved with the modulo operator. Taking \((rear + 1)\,\%\,M\) advances by one, and when the value hits \(M\) it folds to \(0\).

Step 4: Check the boundary. If \(rear = M-1\), then \((M-1+1)\,\%\,M = M\,\%\,M = 0\), which correctly returns to the first slot.

Step 5: The correct increment is \((rear + 1)\,\%\,M\). The correct option is (C).
Was this answer helpful?
0
0