When dynamic allocation of memory is done by using malloc then how is the memory allocated in sequential or in some other format ?

Questions by rpgubba

Showing Answers 1 - 6 of 6 Answers

001edward

  • Sep 20th, 2012
 

Memory allocated is in some other format

  Was this answer useful?  Yes

as malloc returns the base address to a pointer.which can be typecasted.(of type void)...

so firstly the memory allocated is sequentially as per the size of datatype used like int,char,etc...

ex: (int *)a=(int *)malloc(4*sizeof(int));

let the base address be sent to a be=1000;

so next location will be a+4,a+8,a+16..as the size in vytes given by malloc is 4*sizeof(int)=16,gcc compiler int is of 4 bytes.....

this not same as relloc...realloc may return different base address....

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions