Reprint please specify the original link, http://www.cnblogs.com/flyingcloude/p/6992215.html
These days often encounter memcpy these functions, for the memcpy function before the general role of some understanding, but in peacetime to write their own programs, basically do not use this function. Go to Google today, find out the following paragraph of this note:
Description
Prototype: extern void *memcpy (void *dest, void *src, unsigned int count);
Usage: #include <string.h>
Function: the memory area referred to by SRC is copied from count bytes to the memory area of Dest.
Description: The memory area referred to by SRC and dest cannot overlap, and the function returns a pointer to Dest.
Example:
Memcpy.c
#include <syslib.h>
#include <string.h>
Main ()
{
Char *s= "Golden Global View";
Char d[20];
CLRSCR ();
memcpy (D,s,strlen (s));
D[strlen (s)]=0;
printf ("%s", d);
GetChar ();
return 0;
}
So he also wrote a procedure, as follows:
Code
#include <stdio.h>
#include <string.h>
int main ()
{
int secvoltagedelta[132];
for (i = 5; i < i++)
{
Secvoltagedelta[i] = i;
}
printf ("Before memcpy! \ n ");
for (i = 0; i < i++)
{
printf ("%d", secvoltagedelta[i]);
}
memcpy ((void*) &secvoltagedelta, (void*) &secvoltagedelta[128], 4);
printf ("\nafter memcpy!\n");
for (i = 0; i < i++)
{
printf ("%d", secvoltagedelta[i]);
}
printf ("\ n");
}
Originally thought own this program to be able to copy the last 4 numbers of the array to the front, but the result of the run only secvoltage[128] The value copy to the first, thought for a long time did not want to understand.
Then carefully read the description of the memcpy function, and finally found:
Function: the memory area referred to by SRC is copied from count bytes to the memory area of Dest.
is to copy count bytes, just as int is 4 bytes, so only one number is copied.
Reprint please specify the original link, http://www.cnblogs.com/flyingcloude/p/6992215.html
memcpy usage of C language