EmbLogic's Blog

problem with malloc()

if i write

while(1)

{

i=(int *)malloc(sizeof(int));

}

here each location will be assigned to i after 16 addresses.  But why…???  o_O

One Response to problem with malloc()

  1. As i think

    each time stmt in loop executes malloc allocates memory ..which can be any memory address, its not necessary it will be continuous.

    it will give continuous memory if we define no of elements in its arguments like

    malloc(sizeof(int)*4);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>