logo

Memory manipulation functions in C

#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char* argv[]) { int arr1[] = { 3, 4 }; int arr2[] = { 1, 2 }; //memcmp if (memcmp(arr1, arr2, 2 * sizeof(int)) == 0) { printf("Arrays are the same\n"); } else { printf("Arrays are not the same\n"); } // memcpy memcpy(arr1, arr2, 2 * sizeof(int)); printf("%d %d\n", arr1[0], arr1[1]); // memset memset(arr2, 0, 2 * sizeof(int)); printf("%d %d\n", arr2[0], arr2[1]); // memchr if (memchr(arr1, 1, sizeof(int) * 2) != NULL) { printf("Found the byte\n"); } else { printf("Did not find the byte\n"); } return 0; }

Courses with this lesson