Possible Duplicate:
What is x after “x = x++”?
In a loop I have:
int x = 0;
while(int x < 10){
x = x++;
}
Why does this not work?
Possible Duplicate:
What is x after “x = x++”?
In a loop I have:
int x = 0;
while(int x < 10){
x = x++;
}
Why does this not work?
Change x = x++
to just x++
. x++
is unary operation and you don't need to use the assignment operation.
Post increment operator uses the value first and then increments.
x=x++;
Here, we assign X to X (zero to zero) and then we increment X to 1 but we never assign it to anything.
you can change to
X=++X;
and this should give you what you want.
Try converting
x = x++;
to
y = x++; // i.e. y = x, then increment x
x = y;
to understand it.