// 将字符串复制到数组 dest 中
#include <iostream>
#include <string.h>
using namespace std;
int main ()
{
char src[50] = "hello world";
char dest[50];
memcpy(dest, src, strlen(src)+1);
printf("dest = %s\n", dest);
char *s="hello world";
memcpy(dest,s+6,5);//将s中第6个字符开始的5个连续字符复制到dest中
printf("dest = %s\n", dest);
int num=0;
char str[]={"22221111"};
memcpy(&num,str,2);
//'2'对应的ASC码为50,二进制为00110010
//"22"在内存中为00110010 00110010,转化为十进制2^13+2^12+2^9+50=12850
//'0':48
//'1':49
//'2':50
//"22":12850
//"12":12849
//"02":12848 memcpy()会倒叙复制
//"012":3289392
cout<<num;//12850
return 0;
}
memcpy函数
于 2023-08-05 14:27:32 首次发布