Idon'tunderstandhow'i'become4

c#

how does the optput come as
3
3
4
I don't understand how 'i' become 4 for last

code:

int i = 2;
            Console.WriteLine(++i); 
            Console.WriteLine(i++);
            Console.WriteLine(i);

回答

Because you first used the prefix increment operator and then used postfix.

int i = 2;
Console.WriteLine(++i); // i became 3 *before it was used*
Console.WriteLine(i++); // i first used, still 3, and then incremented becoming 4
Console.WriteLine(i); // i is still 4


以上是Idon'tunderstandhow'i'become4的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>