C Standard Libraries C++

memcpy()

Declaration

void* memcpy(void* vpDest, const void* kvpSrc, size_t qCount);

Description

This function copies "qCount" bytes from the buffer "kvpSrc" to the buffer "vpDest." The function returns the pointer "vpDest." The "kvpSrc" and "vpDest" buffers must not overlap.

Example

#include <cstdio>
#include <cstring>

int main()
{
    char caSource[] = "XoaX.net";
    char caDest[10];
    // Copy the first four chars: "XoaX"
    memcpy(caDest, caSource, 4);
    // Add a null-terminator for printing
    caDest[4] = '\0';
    printf("Copied string: %s\n", caDest);

    return 0;
}

Output

memcpy() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.