Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
C++ Tutorial
C++ Language Tutorial - Object Oriented Programing - OOPs History of C++
C++ Language Tutorial - Object Oriented Programing - OOPs Structure of C++
C++ Language Tutorial - Object Oriented Programing - OOPs C++ Datatypes
C++ Language Tutorial - Object Oriented Programing - OOPs Variables
C++ Language Tutorial - Object Oriented Programing - OOPs Constants
C++ Language Tutorial - Object Oriented Programing - OOPs Operators
C++ Language Tutorial - Object Oriented Programing - OOPs Control Structures
C++ Language Tutorial - Object Oriented Programing - OOPs Arrays
C++ Language Tutorial - Object Oriented Programing - OOPs Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Class
C++ Language Tutorial - Object Oriented Programing - OOPs Predefined Functions
C++ Language Tutorial - Object Oriented Programing - OOPs I/O Functions
C++ Language Tutorial - Object Oriented Programing - OOPs String, Character Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Mathematical Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Time Date Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Dynamic Allocation
C++ Language Tutorial - Object Oriented Programing - OOPs Utility Functions
C++ Language Tutorial - Object Oriented Programing - OOPs OOP's Concept
C++ Language Tutorial - Object Oriented Programing - OOPs Special Topics
C++ Language Tutorial - Object Oriented Programing - OOPs Type casting
C++ Language Tutorial - Object Oriented Programing - OOPs Feedback
C++ Language Tutorial - Object Oriented Programing - OOPs Ask Your Doubts
 




memcpy() - Buffer Manipulation Function


Tutorials Cpp

Topic

How is "memcpy()" used in C++?



Explanation

memcpy() buffer manipulation copies the "count" characters from the array block, "str2" to str1". When the arrays overlap behaviour of this function is undefined, this also returns a pointer to "str1". This function simply copies byte by byte characters of the block from the array.

Syntax:
    void *memcpy(void *str1, void *str2, size_t count);

Example:

   #include <stdio.h>
   #include <string.h>
   int main ()
     { 
        char str1[40];
        char str2[]="Memory copy string";
        memcpy (str1,str2,strlen(str2)+1);
        printf ("Array str1 is: %s\nArray 
                  str2 is: %s\n",str1,str2);
        return 0;
     }

Result:
   Array str1 is:Memory copy string  
   Array str2 is:Memory copy string

In the above example, this buffer manipulation is used to copy block of contents of "str2" to "str1", the count is same as the length of "str1".










Note
C++ is one of the most used programming languages in the world. Also known as "C with Classes". Hope you enjoy this tutorial. Do send your feedback or suggestions on this C++ tutorial. This is a copyright content.

Other Links

web hosting