logo

How to properly deal with dynamically allocated memory

#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char* argv[]) { int* arr = calloc(256, sizeof(int)); if (arr == NULL) { return 1; } memset(arr, 0, sizeof(int) * 256); arr = realloc(arr, 64 * sizeof(int)); free(arr); return 0; }
Course thumb

The C programming language made simple