#include <stdio.h>
#include <assert.h>
void *memcpy(void *memTo, const void *memFrom, size_t size) // typedef unsinged int size_t 其大小足以保证存储内存中对象的大小
{
assert((memTo != NULL) && (memFrom != NULL));
char *tempFrom = (char*) memFrom;
char *tempTo = (char*) memTo;
while(size-- > 0)
{
*tempTo++ = *tempFrom++;
}
return memTo;
}
int main()
{
char strSrc[] = "hello World!";
char strDest[20];
memcpy(strDest,strSrc,4);
strDest[4] = '\0';
printf("strDest:%s\n",strDest);
return 0;
}
内存赋值memcpy实现
最新推荐文章于 2023-03-28 15:52:15 发布