Hi there
I am busy swatting, but have hit a speed-bump. It has to do with reversing arrays whilst not allowing use of the array brackets (doing it with pointers in other words).
Basically, I have written this.
Code:
void reverse (int *numbers, int lwb, int upb) {
int *p1, *p2, temp;
p1 = numbers + lwb
p2 = numbers + upb
while (p1 < p2) {
temp = *p1;
*p1 = *p2;
*p2 = temp;
*p1++;
*p2--;
}
...in a bid to swap them. Swapping opposite ends until the pointers are at the same memory address.
However, I've been told that the following would work too. Can you verify?
Code:
while (p1 < p2) {
temp = *p1;
*p1++ = *p2;
*p2-- = temp;
It's just that to me, you're trying to do two things at once with the pointers. Does this not mean that the pointer increments and then assigns the value?
Cheers
M