Which of the following is used for dynamic memory allocation in C?
2026
Which of the following is used for dynamic memory allocation in C?
Answer: D. malloc — ConceptIn the C programming language, memory needed at runtime (rather than fixed at compile time) is managed through standard library functions declared in…
- A.
new
- B.
delete
- C.
create
- D.
malloc
Attempted by 330 students.
Show answer & explanation
Correct answer: D
Concept
In the C programming language, memory needed at runtime (rather than fixed at compile time) is managed through standard library functions declared in the header stdlib.h — malloc(), calloc(), and realloc() for allocation, and free() for deallocation. C has no dedicated operators for this; only C++ adds the new and delete operators, which additionally invoke a constructor or destructor as part of allocation/deallocation.
Application
Declare a pointer variable of the required type, for example int *ptr;
Call malloc with the number of bytes needed, for example ptr = malloc(5 * sizeof(int));
malloc reserves a block of uninitialised memory of that size on the heap and returns a void pointer to it (or a null pointer if the request cannot be satisfied), which is assigned or cast to the pointer type.
The allocated block is used through ptr, and later released with free(ptr); when it is no longer needed.
Cross-check
new and delete are operators defined only by the C++ language specification; a standard C compiler does not recognise them as memory-management constructs.
create is not defined anywhere in the C (or C++) standard library as a memory-management construct.
Among the four given options, only malloc is a valid C construct for dynamic memory allocation, matching ISO C’s specification of malloc in stdlib.h.