+ 2
Why the value of x print 10 first?
int x=10; Console.WriteLine(x++); Console.WriteLine(x); OUTPUT 10 11
3 Answers
+ 1
because x++ perform the operation first means it print the existing value is x and then increase the value is x by 1 and assign it to x. That's why it print 11 next time...
+ 1
x++ post increment
which will assign the value to variable and increment it
x=x+1
above method execute as x=x which is x=10
then x+1 increments the value like 10+1, 11
so you getting the way output
however pre increment was used to increment the value then assign it to variable
0
x++ is a post increment, meaning it increments after x is called. If you want to increment the number first use ++x, which is a pre- increment.