2. Your for() loop is still dividing `iLen/2` every iteration. Presumably the compiler would hoist the division out of the loop, but the code would still add some cognitive friction to future readers of this function. :)
Here's my attempt:
void strrev(char* s)
{
char* a = s;
char* z = s + strlen(s) - 1;
while (a < z)
{
const char c = *a;
*a = *z;
*z = c;
a++;
z--;
}
}
I have interviewed people, but I gave up asking coding questions, since no one could ever do them. And if you keep thumbs-downing people, you don't really get invited to interview any more people.
Nitpick #1:
should be Nitpick #2: "strlen(rev)" is evaluated every iteration of the loop.Nitpick #3:
Those two strlen(rev)'s are evaluated every iteration of the loop.Why not write it like this?