malloc
Allocates uninitialised memory on the heap.
Easy
int *a = malloc(n * sizeof *a);
if (!a) { /* out of memory */ }
Check for NULL; watch for n * size overflow with huge n.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.