Tsallaka zuwa abun ciki
Justice Tech School

memcpy and memset

memcpy copies bytes and memset fills them. Sizes are in bytes.

Example
#include <stdio.h>
#include <string.h>

int main(void) {
  int a[3] = {1, 2, 3}, b[3];
  memcpy(b, a, sizeof a);
  memset(a, 0, sizeof a);
  printf("%d %d\n", b[2], a[2]);
  return 0;
}

Result

3 0

Exercise

Fill bytes.

(p, 0, n)

Quiz Test

Which header is it in?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.