Friday, May 16, 2008

What is meant by malloc function

Malloc function will allocate memory for pointers. Whenever you define a pointer it will just allocate 4 bytes to store the address of pointer and no memory for variable storage.Using malloc you can assign memory so that we can store variables and access through pointer

for e.g

int *p;
*p=5; /* It will generate error as no memory allocated for pointer */


int *p;
p= malloc (4); /* allocates 4 bytes */
*p=5; /* Now it works fine */

No comments:

Contributors