Vidyalelo
C Programming · Q51

Memory Allocation

Programming · C Programming · question 51

Q51

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

Answer: Option D

Solution

Answer: Option D
No explanation is given for this question Let's Discuss on Board