1. # include <string. h>
Void * memcpy (void * To, const void * From, size_t count );
Function:FromCopyingCountCharactersToAnd returnToPointer. IfToAndFromOtherwise, the function behavior is uncertain.
Note: (1) the first parameter is the target pointer, and the second parameter is the starting pointer. Do not make a mistake.
(2) During the copy process, the unit of counting is characters, that is, bytes.
Example:
# Include <iostream>
# Include <cstring>
Using namespace STD;
Int main (){
Int A [4] = {1, 2, 4 };
Int B [4];
Memcpy (B, A, 4*4); // copy the one-dimensional int Array
For (INT I = 0; I <sizeof (B)/4; I ++)
Cout <B [I] <"";
Cout <Endl;
Int C [2] [2] = {1, 2, 3, 4}; // copy the two-dimensional int Array
Int d [2] [2];
Memcpy (D, C, 4*4 );
For (INT I = 0; I <2; I ++ ){
For (Int J = 0; j <2; j ++)
Cout <D [I] [J] <"";
Cout <Endl;
}
Char E [2] [2] = {'A', 'B', 'C', 'D'}; // copy a two-dimensional char array
Char f [2] [2];
Memcpy (F, E, 4 );
For (INT I = 0; I <2; I ++ ){
For (Int J = 0; j <2; j ++)
Cout <F [I] [J] <"";
Cout <Endl;
}
}
Another example program:
Struct map {
Int;
String B;
};
Int main (){
Struct map a [2] = {4, "hello"}, {1, "world" }}, B [2];
Memcpy (B, A, sizeof (MAP) * 2 );
Cout <B [0]. B <Endl;
}
~~~~~~~~~~~~~~~~~~~~~