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.
Asked
Active
Viewed 31 times
2
-
More a simple coding question. Not really a question about the Arduino. – sempaiscuba Apr 09 '18 at 00:31
-
which programming language? – jsotola Apr 09 '18 at 01:48
-
use http://symbolhound.com/ for research – jsotola Apr 09 '18 at 01:51
2 Answers
3
The % is the modulo operator in C/C++, which basically means:
- Divide the value to the left of the
%by the value to the right of it - 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