...and where you are in the array, hence the temp variable.
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).
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 :)