1/4
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is Dynamic Memory Allocation in C?
The process of allocating memory manually on the heap during runtime using functions from the <stdlib.h><stdlib.h> library.
What is the function of malloc()?
The malloc() function is used to allocate memory dynamically during the execution of a program. It returns a pointer to the beginning of the allocated memory block or NULL if the allocation fails.
Usage: ptr=(int∗)malloc(n∗sizeof(int));
The function of malloc() is to allocate a specified number of bytes in memory on the heap, returning a pointer to the allocated memory.
How does calloc() differ from malloc()?
It stands for Contiguous Allocation. Unlike malloc(), calloc() initializes all bits in the allocated memory to zero and takes two arguments: the number of elements and the size of each element.
Usage: ptr=(int∗)calloc(n,sizeof(int));
What is the purpose of the free() function?
It is used to deallocate or release the memory previously allocated by malloc(), calloc(), or realloc() to prevent memory leaks. Usage: free(ptr);
Which function is used to change the size of previously allocated memory?
The realloc()Re-allocation) function. It modifies the size of the memory block pointed to by a pointer while attempting to preserve the original content.
Usage: ptr=realloc(ptr,new_size);