Professional Documents
Culture Documents
(DMA)
Need of Dynamic memory allocation
Example:
ptr=(int*)malloc(100*sizeof(int));
This statement will allocate 400bytes and the pointer points to the
address of first byte of memory
Syntax:
void *calloc(size_t nmemb, size_t size);
Typecasting:
ptr=(cast-type*)calloc(n,element-size);
Example:
ptr=(int*)calloc(100,sizeof(float));
This statement will allocate 400bytes and the pointer points to the
address of first byte of memory
The free() function frees the memory space pointed to by ptr, which
must have been returned by a previous call to malloc(), calloc() or
realloc()
Syntax:
void free(void *ptr);
Syntax: