0

tell me why the output of this code is 3 ???

why is the output of this code 3 ??? int y = 3; int x = 10; int z = y - (x % --y); Console.Write(z);

10th Nov 2021, 11:08 AM
Роман Жигунов
Роман Жигунов - avatar
5 odpowiedzi
+ 3
% operator gives the remainder of a division. So, z=y-(x%--y) z=3-(10%2) z=3-0 z=3 And then Z is being printed to the console =)
10th Nov 2021, 11:11 AM
Rishi
Rishi - avatar
+ 2
Роман Жигунов I don't understand what you're saying. "Won't y be equal to 2?" y is equal to 2 right? At first y was given the value 3, but the expression --y decremented the value of y by 1 and made it 2
10th Nov 2021, 2:58 PM
Rishi
Rishi - avatar
+ 2
Y isn't decremented until - - y appears. So, the first y is still 3 because it appears before the second.
10th Nov 2021, 5:16 PM
Mélodie Bernard
Mélodie Bernard - avatar
+ 1
when using the step with entry function (F11), it shows me that y is assigned the value 2 won't y be equal to two? z = 2 - (10% 2);
10th Nov 2021, 11:34 AM
Роман Жигунов
Роман Жигунов - avatar
+ 1
Melodie Bernard, this is what I needed, thanks)
10th Nov 2021, 5:37 PM
Роман Жигунов
Роман Жигунов - avatar