malloc() in C — a practical guide to C malloc with clear examples you can reuse in real projects.
C Programming Tutorial Series (64/102). Prefer one article? Read the complete C programming tutorial.
Short description
Always check for NULL on failure.
malloc
int *a = malloc(10 * sizeof *a);
if (!a) {
perror("malloc");
return 1;
}
free(a);