What is the calculation behind the '%' operator in c++ ?
I understand that it gives the remainder of a division of 'a' by 'b' in 'a%b'.
It also yields 20 for 20%100, how is this working?
does it yield the dividend if the dividend<divisor? in other words, if the quotient is < 1 , does it return 'a' itself?
Last edited on
It gives the remainder of the division, period.
20 % 100:
20/100 is 0, remainder 20, hence you get 20.
for integers n, q , p and r; n = q*p +r where r is always less than the modulo number.