EmbLogic's Blog

How to estimate memory alocated under Double Pointer

If we use single malloc for a double pointer then it simply means that the memory is allocated to the for the external Pointer

i.e, malloc(**ptr) -> Memory is allocated only for external pointer of  *(*ptr) which is allocated in form of array. But to provide (*ptr) a memory location , we have to malloc() it again as follows:

malloc(*ptr) ->Now memory is allocated for *ptr .

To  check the amount of memory allocated under **ptr , just print using %d format specifier and as an argument to printf call sizeof(**ptr) .

i.e,

printf(“The size under **ptr is :%d \n”,sizeof(**ptr));

 

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>