revers and array with only pointers :D

So i have this array
int a[] = {45,67,89,4,3,101};

and need to just revers it to

int a[]= {101, 3, 4, 89, 67, 45};

using no [] and only pointers.

This is for C we aren't allowed to use C++ syntax.

Can anyone help? I have the basic idea that i have to swap each element by swapping their address using points just not sure how to!

Thanks!
Just use a normal reverse algorithm, just replacing all instances of the subscript operator with pointer arithmetic.

array[n] == *(array + n)
I can't use [] anywhere in it except just declaring the array
Zhuge was just trying to show two equivalent bits of code, and he's right! Instead of the subscript operator, one can just use some basic pointer arithmetic and a dereference operator.
*(array + n) is the same as array[n].

EDIT: Typo! Gah! :)

Happy coding!

-Albatross
Last edited on
oh ok perfect works now:D

Thanks!
Topic archived. No new replies allowed.