+ 2
Please explain me why in this code output is 14.
Such a code: int x = 19; int y = x%3; while (y<3) x -= ++y; Console.WriteLine(x); Visual studio issues 14. I tried to understand the difference between ++y and y++ and could not. Please help me.
4 Réponses
+ 6
You already got detailed explanation about the code from Nasif Rahman 's answer.
Further check this lesson..
It'll clear your doubts between prefix and postfix.
https://www.sololearn.com/learn/CSharp/2590/?ref=app
+ 3
First y =1
x-=++y //x=19,++y=2(y=y+1),x=x-y=17
x-=++y //x=17,++y(y=y+1)=3,x=x-y=14
I hope you understand!
+ 2
Thank you very much, guys! Nasif Rahman Vadivelan
Can you also describe an exactly the same example, but with y++?
Then I will certainly understand everything. Thanks!
+ 2
https://code.sololearn.com/c8xhfsCXgt74/?ref=app
https://code.sololearn.com/cc5B9nQA82yR/?ref=app
a = 0
++a = 1
a == 1 //true
b = 0
b++ = 0 (if b++==0 //true, if ++b ==0 //false)
b == 1 //true