Arithmic Operators | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Arithmic Operators

I hope I'll be able to get my question across, it's quite difficult for me to explain. Here are to pieces of code that I'll refer to in my question below. In the C# I've come across the following codes: int a=4; int b=6; b=a++ Console.WriteLine(++b); Output=5 int x=15; int y=6; x%=y; Console.WriteLine(x); Output=3 What I fail to understand is: In the first piece of code b gets the value of a, but in the second piece, x doesn't get the value of y because instead x%=y gets to be x%y? So why isn't b allowed to keep its value (in the first code) when in the second code, x gets to keep its value, even though it says x%=y? Why doesn't x gets the value of y?

7th Feb 2017, 10:20 PM
Estroyer
Estroyer - avatar
2 Answers
+ 4
x%=y is a short way of writing x = x % y. b = a++ is equivalent to b = a; a = a + 1;
7th Feb 2017, 10:23 PM
Zilvinas Steckevicius
Zilvinas Steckevicius - avatar
0
This is a very late reply but thanks for the explanation! It helped me figuring it out!
4th Sep 2017, 7:36 PM
Estroyer
Estroyer - avatar