>> How does C++ test the expression? Does it increase the value of k then test the expression or does it first test then increase the value of k

in case of operator ++ it depends.

1.) if you use preincrement operator (++k). then C++ first increments k, and then use it in any expression that ++k is in.

2.) if you use postincrement operator (k++). then C++ use k for computing the expression that k++ is in, and afther that increments k.

In your piece of code you use postincrement operator and thats why you have k = 12 value at the end of loop.

value before comparation increment

comparation

k = 0, (0<=10), k = k + 1 = 1;

k = 1, (1<=10), k = k + 1 = 2;

...

k = 9, (9 <=10), k= k + 1 = 10;

k = 10, (10 <= 10), k = k + 1= 11;

k = 11, (11 <= 10); this is the end of loop, but you still have k = k+1 = 12!

If you have used ++k, you wold have k = 11 at the end.

value before increment comparation

comparation

k = 0, k = k + 1 = 1 k = k + 1 = 1;

k = 1, k = k + 1 = 2 k = k + 1 = 2;

...

k = 9, k = k + 1 = 10 k= k + 1 = 10;

k = 10, k = k + 1 = 11 (11 <= 10), false, end of loop.

For second question, I have really no idea :-).