What is the use of memcpy function in C language
This article mainly shows you "what is the use of memcpy function in C language", the content is easy to understand, clear, hope to help you solve doubts, the following let Xiaobian lead you to study and learn "what is the use of memcpy function in C language" this article.
Memcpy
Function: memory copy
Function prototype:
Void * memcpy (void * dest, const void * src, size_t count)
Use:
Format: memcpy (destination, original, memory size you want to manipulate (in bytes))
Copy the "Parameter 3" byte content starting from "Parameter 2" to "Parameter 1"
The memecpy function is similar to strncpy.
Example:
# include # include # include int main () {int aa [] = {1pr 2pc 3P 4}; int bb [10] = {0}; memcpy (bb, aa, 4 * sizeof (int)); / / copy the contents of 4 bytes (each int type is 4 bytes) in the aa array to the bb array for (int I = 0; I)
< 10; i++) //打印bb数组全部数据 { printf("%d ", bb[i]); } } 最后bb字符串中前4*4个字节的内容被改为aa的内容
Note: memcpy cannot copy overlapping memory.
# include # include # include int main () {int aa [] = {1, 2, 7, 8, 9, 10}; my_memcpy (aa + 2, aa, 24); for (int I = 0; I < 10; iBex +) {printf ("% d", aa [I]);}}
Output:
This problem occurs when copying overlapping memory.
These are all the contents of the article "what is the use of memcpy functions in C language". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!