On this page
  1. memcpy
  2. Include
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

memcpy

Prev: string.h | Up: string.h | Next: memmove
Rel: string.h, stdlib.h & string.h Guide
Ref: cppreference — memcpy
Tags: #public #prog #c #stdlib #string #tier/core


Include

#include <string.h>

Signature & Overview

void *memcpy(void *restrict dst, const void *restrict src, size_t n);

Copies n bytes from src to dst; undefined behavior if source and destination overlap.

Notes & Pitfalls

Example

#include <assert.h>
#include <string.h>

int main(void) {
    int src[2] = {10, 20}, dst[2] = {0};
    memcpy(dst, src, sizeof(src));
    assert(dst[0] == 10 && dst[1] == 20);
}

Linked from

Related notes