Prefix and Postfix | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Prefix and Postfix

When looking at Postfix Int x = 3; Int y = x++; Console.WriteLine(x+(ā€œ ā€œ)+y); // x output is 4, y output is 3 But how come (int y) doesnā€™t also get a +1 since we did y = x++, because if the variable y equals x++ shouldnā€™t it also be 4?

9th Oct 2020, 12:56 AM
Dr.Tevvy Beats
Dr.Tevvy Beats - avatar
1 Resposta
+ 3
If you assign x++ to y, you are assigning the original value of x rather than x+1. But if you assign ++x, you are assigning x+1. Of course eventually the x is increased by 1.
9th Oct 2020, 1:06 AM
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ - avatar