Memory Allocation on C related Questions and Answers


Question :   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()?
1. x=(int*)malloc(10);
2. x=(int*)malloc(10,sizeof(int));
3. x=malloc(int 10,sizeof(int));
4. x=(int*)malloc(10*sizeof(int));
Answer :   4 - x=(int*)malloc(10*sizeof(int));  

* Be the First to Post a Comment.

Submit comment :


Captcha Image
Reload

Ask Question

Captcha Image
Reload

Note : Name and Email never shown.





Subscribe


Become a part of EducationForever. Subscribe to our FREE Newsletter