ProgrammingHardTCS NQT · Infosys

A circular buffer of size n = 5 steps back from index 0 with (idx + n - 1) % n. What index results?

  1. A. 0
  2. B. 4
  3. C. 5
  4. D. 1

Correct answer: B. 4

Adding n - 1 before the modulo keeps the value non-negative in unsigned or signed code alike. (0 + 4) % 5 = 4.

More C Programming questions

Exams that ask this topic