DYNAMIC MEMORY ALLOCATION

0.0(0)
studied byStudied by 0 people
0.0(0)
call with kaiCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/4

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:11 PM on 12/25/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

5 Terms

1
New cards

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.

2
New cards

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.

3
New cards

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));

4
New cards

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);

5
New cards

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);