8. Storage Management
void ∗malloc(size_t n)
– malloc() allocates blocks of memory
– returns a pointer to unitialized block of memory on success
– returns NULL on failure.
– the returned value should be cast to appropriate type using ().
int ∗ip=(int ∗)malloc(sizeof(int)∗100)
void ∗calloc(size_t n, size_t size)
– allocates an array of n elements each of which is ’size’ bytes.
– initializes memory to 0
void free(void ∗)
– Frees memory allocated my malloc()
– Common error: accessing memory after calling free
이전페이지 / 9 / 다음페이지