Talking about the difference between strcpy and memcpy

The difference between strcpy and memcpy

  1. The copied content is different.
      Strcpy can only copy strings, while memcpy can copy any type of content. Strcpy will copy'\0', and memcpy can copy anything.
  2. The copy method is different. When
      strcpy is copying, there are two parameters, and it is easy to overflow during the cut copy process. When memcpy is copying, the parameters are three. The more parameter is the number of bytes copied, which determines the length of the copy.
  3. For different purposes
      , strcpy is usually used when copying strings, and memcpy is generally not used when copying other types of data. Instead, memmove, an evolved version of memcpy, solves the memory overlap problem.

Guess you like

Origin blog.csdn.net/weixin_43580319/article/details/112770296