Hmm, suppose n is even, say n=6.
Then the highest index you will get inside your loop is i=6.
Which 2 elements will be exchanged then?
If you are asking about the code i just posted, then the 2 elements will be exchanged are x and x.
When the swapping loop starts, the values present in x, x and x gets stored in the tmp and are exchanged. For example, value in x gets exchanged with x, x gets exchanged with x and x exchange with x. In the swapping loop, the value of i cannot reach 6.
[offtopic]Can you suggest me some good resources for learning C++? I missed some of my C++ classes on the looping section and i had to learn for-loop on my own. :( [/offtopic]