int n = 0;
for( int m = 0; m < 5; m++){
n = n++;
print(n);
}
Lets look at JAVA first.
In java, while executing the statement
n = n++
what actually happens is, an intermediate variableis created. It stores the original value of n. so the sequence is
temp = n;
n++;
n = temp;
0 0 0 0 0
Now lets look at C and C++.
In these compilers, there is Direct Memory Operations with Pointers without the use of intermediate variables.
So the result in this case is what many people would expect. That is
1 2 3 4 5
No comments:
Post a Comment