Differences between memcpy and strcpy

Source: Internet
Author: User

Prototype: extern void * memcpy (void * dest, void * src, unsigned int count); usage: # include <string. h> function: copy count bytes from the memory area indicated by src to the memory area indicated by dest. Note: the memory areas specified by src and dest cannot overlap. The function returns a pointer to dest. Note: Compared with strcpy, memcpy does not end when it is met, but will certainly copy n Bytes. Example: // memcpy. c # include <stdio. h> # include <string. h> int main (int argc, char * argv []) {char * s = "Golden Global View"; char d [20]; clrscr (); memcpy (d, s, strlen (s); d [strlen (s)] =; printf ("% s", d); getchar (); return 0 ;} capture view # include <string. h> int main (int argc, char * argv []) {char * s = "Golden Global View"; char d [20]; memcpy (d, s + 14,4 ); // memcpy (d, s + 14 * sizeof (char), 4 * sizeof (char); can also d [4] =; printf ("% s ", d); getchar (); return 0;} output result: View initializes the array char msg [10]; memcpy (msg, 0, sizeof (msg ));

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.