Table of Contents
This guide covers the function memcpy ()() in c with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.
Declare the Function Memcpy ()() in C
Below is the declaration for memcpy () in C:
void * memcpy ( void * str1 , const void * str2 , size_t n )
Parameters
Str1 - This is the pointer to the destination array, where the content to be copied, cast into a pointer of type void *.
Str2 - This is the pointer to the data source to copy, cast into a pointer of type void *.
n - This is the number of bytes to be copied.
Returns the Value
This function returns a pointer to the destination string, str1.
For Example
The following program C illustrates the usage of memcpy () in C:
#include #include struct { char name [ 40 ]; int age ; } person , person_copy ; int main () { char myname [] = "Nguyen Hoang Nam" ; /* su dung ham memcpy de sao chep chuoi: */ memcpy ( person . name , myname , strlen ( myname )+ 1 ); person . age = 46 ; /* su dung ham memcpy de sao chep struct: */ memcpy ( & person_copy , & person , sizeof ( person ) ); printf ( "person_copy = %s, %d n" , person_copy . name , person_copy . age ); return 0 ; }
Compiling and running the above C program will result:
According to Tutorialspoint
Previous article: Function memcmp () in C
Next lesson: memmove function in C
FAQ
What should I check before following these steps?
Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.
Why might the process not work?
Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.
Can I undo the changes if necessary?
That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.
Reader Comments 0
Sign in with email or Google to join the discussion.