
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
memcpy() function in C/C++
The function memcpy() is used to copy a memory block from one location to another. One is source and another is destination pointed by the pointer. This is declared in “string.h” header file in C language. It does not check overflow.
Here is the syntax of memcpy() in C language,
void *memcpy(void *dest_str, const void *src_str, size_t number)
Here,
dest_str − Pointer to the destination array.
src_str − Pointer to the source array.
number − The number of bytes to be copied from source to destination.
Here is an example of memcpy() in C language,
Example
#include <stdio.h> #include <string.h> int main () { char a[] = "Firststring"; const char b[] = "Secondstring"; memcpy(a, b, 5); printf("New arrays : %s\t%s", a, b); return 0; }
Output
New arrays : SeconstringSecondstring
In the above program, two char type arrays are initialized and memcpy() function is copying the source string ‘b’ to the destination string ‘a’.
char a[] = "Firststring"; const char b[] = "Secondstring"; memcpy(a, b, 5);
- Related Articles
- memcpy() in C/C++
- Write your own memcpy() in C
- Write your own memcpy() and memmove() in C++
- iswblank() function in C/C++
- iswpunct() function in C/C++
- strchr() function in C/C++
- strtod() function in C/C++
- memmove() function in C/C++
- atexit() function in C/C++
- raise() function in C/C++
- mbrlen() function in C/C++
- strftime() function in C/C++
- iswlower() function in C/C++
- towupper() function in C/C++
- iswdigit() function in C/C++

Advertisements