Interview Questions and Answers :: Amazon
Home > Experience Archives > Amazon > Interview Question Set > Discussion
2. Allocate the memory for 2 int*. and free it. Now I had question. How free will know how many byte memory has to free.
Answer:
int *p;
p = (int *) malloc(2 * sizeof (int));
When memory allocation is done, the actual heap space allocated is one word larger than the requested memory. The extra word is used to store the size of the allocation and is later used by free( )
Vijay K
29 Oct, 2017 12:58 PM
int *p;
p = (int *) malloc(2 * sizeof (int));
When memory allocation is done, the actual heap space allocated is one word larger than the requested memory. The extra word is used to store the size of the allocation and is later used by free( )
p = (int *) malloc(2 * sizeof (int));
When memory allocation is done, the actual heap space allocated is one word larger than the requested memory. The extra word is used to store the size of the allocation and is later used by free( )
Report Error
Report Error
Please Login First Click Here