What is the value of "val" after for's first loop?
for (int val = 1; val <= 10; ++val)
cout << val <<endl; //I expected 2, but the result was 1.
for (int val = 1; val <= 10; val++)//Result: 1
cout << val <<endl; //I expected 1, the result was 1.
Why got the same value?
I looked at the explanation, but do not quite understand why the results came that way:
" The postix increment operation occurs after the operand is evaluated.
In the prefix form, the increment takes place before the value is used in expression evaluation, so the value of the expression is different from the value of the operand.
See section 1.9.17 in the C++ standard for more information."
Please give me the specific answer. Thanks!