In this code, the line:
rev(&orr[1], numentries - 2);
results in the first and last numbers in the array reversing and leaves the middle numbers untouched. Why is it not the reverse case, that is why is it not the case that the the first and last numbers are untouched and the middle numbers are reversed? I thought that &orr[1] would start the reverse function from the second element of the array and that numentries - 2 would leave the last entry untouched.
Also, when I try to preview messages in Firefox and Chrome it does not work, that is a window opens but it just has my name, no message.
First you call rev(orr, numentries); which reverses the whole array, then you call rev(&orr[1], numentries - 2); which reverses the middle numbers so that they end up in their original positions. The effect of both these calls together is that only the first and last numbers are swapped.
I also noticed the program requires you to enter one extra number that is not added to the array. To fix this you should check to see if numval is less than size before reading the number.
while (numval < size && cin >> val) {
Also, when I try to preview messages in Firefox and Chrome it does not work, that is a window opens but it just has my name, no message.
Unfortunately, this is a forum bug. If you first post the message and then edit it you will be able to view the preview.
I thought that &orr[1] would start the reverse function from the second element of the array and that numentries - 2 would leave the last entry untouched.
Yes, that's exactly what it does!
However, you have called the function rev TWICE.
The first time, on line 15, reverses everything.
The second time, on line 18, reverses just the internal elements
The net effect is that the internal elements are reversed ... and then reversed back again (so no overall change), whilst the outermost elements are just reversed once (so end up being swapped).
Note: There's something wrong with your input routine.
Thanks very much. I didn't realise that after the first call the values were staying reversed. Is there then a way of making the initial call and leaving the elements in their original order? (I mean without writing another function to reverse them back.)