ProgrammingHardTCS NQT · Infosys
A circular buffer of size n = 5 steps back from index 0 with (idx + n - 1) % n. What index results?
- A. 0
- B. 4
- C. 5
- 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
- A qsort comparator orders the elements in descending order. After sorting {5, 9, 2}, what is the first element?
- uint32t x = 491u; What is (x >> 3) & 7? (491 is 0x1EB.)
- uint32t r = 2147483648u % 1000u; What is r?
- uint32t p = 65536u 65537u; What is p?
- int a[] = {1, 2, 3, 4, 5}; int p = a; p += 3; printf("%d", p--); What is printed?
- int x = 10; int px = &x; px += px 2; What is x?