logo

How to use malloc to dynamically allocate memory

#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char* argv[]) { int* p = (int*) calloc(3, sizeof(int)); p[1] = 3; p[2] = 90; printf("The values are %d, %d and %d\n", p[0], p[1], p[2]); free(p); return 0; }
Course thumb

The C programming language made simple