Postfix and Prefix increment and decrement

suggest change

Postfix increment X++ will add 1 to x

var x = 42;
x++;
Console.WriteLine(x); // 43

Postfix decrement X-- will subtract one

var x = 42
x--; 
Console.WriteLine(x); // 41

++x is called prefix increment it increments the value of x and then returns x while x++ returns the value of x and then increments

var x = 42;
Console.WriteLine(++x); // 43
System.out.println(x); // 43

while

var x = 42;
Console.WriteLine(x++); // 42
System.out.println(x); // 43

both are commonly used in for loop

for(int i = 0; i < 10; i++)
{
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents