+ 2

Anybody can explain how the output is 1

int x = 9; int y = 4; int z = x++-y--+(x+y); Console.Write(--z % 2);

1st May 2018, 1:34 PM
santosh kumar
santosh kumar - avatar
2 Respostas
+ 13
int z=x++ - y-- +(x+y); 9 - 4 + (10+3) z= 9-4+13 = 18 --z=17 17%2= 1;
1st May 2018, 1:39 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 2
x++ and y-- means post increment and increment value after line 3 i.e here, int z=x++-y--+(x+y)=9-5+13=18 and when --z%2 was used then here --z is pre decrement so it will decrete value by 1 ie --z=17 so output 17%2=1
5th May 2018, 1:29 PM
Pritish Rohilla
Pritish Rohilla - avatar