面试题----实现memcpy
#include <stdio.h> void *memcpy(void *memTo,const void *memFrom,size_t size) { if(memTo == NULL || memFrom == NULL) return NULL; char *p = (char *)memTo; char *q = (char *)memFrom; while(size > 0) { *p = *q; p++; q++; size--; } return memTo; } int main() { char strSrc[] = "Hello World!"; char strDest[20]; memcpy(strDest,strSrc,4); strDest[4] = '\0'; printf("赋值结果为:%s\n",strDest); return 0; }