2

Can someone interpret the code in the Title line for me? Specifically the function of the "%" sign? It is a line having to do with a 100 element circular buffer.

2 Answers2

3

The % is the modulo operator in C/C++, which basically means:

  1. Divide the value to the left of the % by the value to the right of it
  2. Discard the quotient and keep only the remainder.

For instance, 10 % 5 = 0, because 10/5 = 2 with no remainder. Whereas 11 % 5 = 1, because the remainder of the division is 1.

In your case, the modulo operator is likely being used to keep the value of put_index less than 100 at all times. If it became 100 because of the operation put_index = put_index + 1, then the modulo operation would make the 100 into 0, so put_index will keep incrementing 0–99 repeatedly.

R Zach
  • 131
  • 2
1

In C the % symbol is the modulo operator : https://en.m.wikipedia.org/wiki/Modulo_operation

Andre Courchesne
  • 676
  • 5
  • 11