Interview Questions

156. Write the memmove function in C. ......

Microsoft Interview Questions and Answers


(Continued from previous question...)

156. Write the memmove function in C. ......

Question:
Write the memmove function in C. Given two arrays a1 and a2, copy a1 in to a2. Beware aware of the fact that a1 may be overlapping a2 in memory.


maybe an answer:


void memmov(int *s, int *t, int n) { if (s <= t) { int *se = s + n - 1; int *te = t + n - 1; while(se >= s) *te-- = *se--; } else { int *sb = s; int *tb = t; while(sb < s+n) *tb++ = *sb++; } }

(Continued on next question...)

Other Interview Questions