0

What is the difference between 15%6 and 15%=6 ?

6th Jul 2016, 8:50 AM
Jansen Tanu
Jansen Tanu - avatar
2 Answers
+ 1
15%6== 3 and 15%=6 == error. The Console.WriteLine asks for the variable 'x'. 'int x = 15' and 'int y = 6' declare that 'x' and 'y' exist and are variables of type integer while also assigning a value to them (15 and 6 respectively). 'int x' is then modified when it is called again as 'x' (since it was declared before the program already knows it's an 'int') which is now given a new value of the remainder of its original value divided by 'y'. Hence x %= y (which is the same as [variable x] = [value x]%[value y], it's just more elegant to write it as x %= y). I hope that helps.
7th Jul 2016, 7:44 AM
Greg
0
@Greg Ooooh. I see...
7th Jul 2016, 8:36 AM
Jansen Tanu
Jansen Tanu - avatar