Suppose we have a one dimensional array, named 'x', which contains 10 integers. Which of the following is the correct way to allocate memory dynamically to the array 'x' using malloc()?
A. x=(int*)malloc(10);
B. x=(int*)malloc(10,sizeof(int));
C. x=malloc(int 10,sizeof(int));
D. x=(int*)malloc(10*sizeof(int));
Answer: Option D
Related Questions on Memory Allocation
In C, which header file should be included to use dynamic memory allocation functions?
A. stdlib.h
B. malloc.h
C. memory.h
D. alloc.h
What is the purpose of the 'malloc' function in C?
A. To allocate dynamic memory
B. To allocate static memory
C. To deallocate memory
D. To find memory leaks
Which function is used to allocate an array of elements in C?
A. calloc()
B. malloc()
C. alloc()
D. array()
What does the 'calloc' function in C do?
A. Allocates and initializes memory to zero
B. Allocates memory and leaves it uninitialized
C. Deallocates memory
D. Checks for memory leaks

Join The Discussion