Comment on Ask HN: Favorite pointer tricks in C?parentComments−visualphoenix15yShouldn't that be --j in your reverse function?Anyhow, when asked to write those on a blackboard, I typically do this: size_t strlen(char* start) { char* end=start; while(*end) ++end; return (end-start); } and void reverse(char* i) { char* j=(i+strlen(i)-1); for (; i < j; ++i,--j) { *i ^= *j; *j ^= *i; *i ^= *j; }−Locke168915yYup, --j.Also, the XOR version probably isn't worth the complexity.−visualphoenix15yTrue in practice, but on a blackboard during an interview, it obviates the need to recode for the follow-up "now reverse the string in place" request.
Comments
Shouldn't that be --j in your reverse function?
Anyhow, when asked to write those on a blackboard, I typically do this:
andYup, --j.
Also, the XOR version probably isn't worth the complexity.
True in practice, but on a blackboard during an interview, it obviates the need to recode for the follow-up "now reverse the string in place" request.