Skip to main content
C Code Reorder Medium +20 XP

Malloc Pattern

Arrange the correct memory allocation pattern.

Click lines in the correct order

Available lines4 left

Your order

Click lines above to build your solution.

Show answer and explanation

Answer: int *arr = malloc(n * sizeof(int)); if (!arr) return 1; arr[0] = 42; free(arr);

Allocate, check for NULL failure, use the memory, then free it.

Hint: Always check malloc for NULL before use.

What this challenge tests

Code Reorder in C: malloc, memory.

Related challenges