memcpy c++ code example
Example 1: memcpy c++ usage
#include<cstring>
int main(){
char a[4],b[]={"hello"};
memcpy(a,b,strlen(b)*sizeof(char));
}
Example 2: c memcpy
int dst[ARRAY_LENGTH];
memcpy( dst, src, sizeof(dst) );
Example 3: memcpy library cpp
#include <cstring>
Example 4: c++ memcmp
#include <stdio.h>
#include <string.h>
int main ()
{
char buffer1[] = "DWgaOtP12df0";
char buffer2[] = "DWGAOTP12DF0";
int n;
n=memcmp ( buffer1, buffer2, sizeof(buffer1) );
if (n>0) printf ("'%s' is greater than '%s'.\n",buffer1,buffer2);
else if (n<0) printf ("'%s' is less than '%s'.\n",buffer1,buffer2);
else printf ("'%s' is the same as '%s'.\n",buffer1,buffer2);
return 0;
}