Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • memcpy() in C

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 683
    Comment on it

    memcpy()

    This method as the name suggest memcpy() i.e memory copy is used to copy a number of bytes i.e a block of memory from one location to another location.

    Syntax of memcpy():

    void * memcpy(void *to, const void *from, size_t numBytes);
    

    Program to demonstrate memcpy() method in C:

    /* A C program to demonstrate working of memcpy */
    #include <stdio.h>
    #include <string.h>
    
    int main ()
    {
      char str1[] = "Demo";  
      char str2[] = "First";  
    
      puts("str1 before memcpy ");
      puts(str1);
    
      /* Copies contents of str2 to sr1 */
      memcpy (str1, str2, sizeof(str2));
    
      puts("\nstr1 after memcpy ");
      puts(str1);
    
      return 0;
    }

    Output:

    str1 before memcpy

    Demo

    str1 after memcpy

    First

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: