You don't need a temporary variable for "p" -- if the task is to write a function, you must have a pointer with the address of the start of the array, not an array variable as such. And yeah, you need some way to tell the length.
Write it out to see.
So it still doesn't work, even if you use a function to "cheat" and get a "free" pointer (which, by the way, wasn't what the task said).
Here it is with a 4-element array, a[0] through a[3]:
a=[100,200,300,400]
a[0] ^= a[3]
a[3] ^= a[0]
a[0] ^= a[3]
a[1] ^= a[2]
a[2] ^= a[1]
a[1] ^= a[2]
a
[400, 300, 200, 100]
(Pretend this list is an array, it's just for illustrative purposes)http://www.lysator.liu.se/faq/c-faq/c-2.html
The general point is that interviews of this type are counterproductive.
If you want to posit any kind of sane question, then you can have a sane solution.
That's what I said a few posts ago.
> You can't claim to have a solution for the problem if it only works for a
> fixed input, and if the solution itself would be different for different
> inputs.
"Reverse this array". Done. "Reverse an unspecified array of arbitrary length" is a different problem :)