malloc and free Functions in C Programming Language Video Tutorial

In this C programming language video tutorial / lecture for beginners video series, you will learn about the malloc() and free() functions used for dynamic memory allocation in detail with example.

you will learn the syntax of malloc function and free functions, what are the parameters required for the malloc and free functions, how malloc function allocates the bytes of memory from the heap,how free function frees the allocated memory.

You will learn how to create the pointer and allocate the memory dynamically for integers,float and character datatype, and also learn how to allocate the memory dynamically depending on the user input to store a string in detail with an example.

Visit for more free computer programming video tutorials.

Learn Programming in HINDI at our youtube channel

Catch us on Social Media


Angelo Soriano says:

Hi Anil! I tried it without casting and it worked, do we really need to cast malloc functions? Is it good practice to cast malloc or not?

Samantha Tite Webber says:

Thank you for showing us this in C. Well-explained video.

Hà Chí Hào says:

what does fflush() do ?

Sagar Jaiswal says:

While taking input of string from the user and printing it why did you use gets(p) and puts(p)… You should be using gets(*p) and puts(*p) right?..

Meruem Sama says:

Firstly, thank you for awesome tutorials. There is something that I could not understand. If you help, I will be thankful.

I want 3 bytes from memory and then equal that to an int. Each integer variable was 4 bytes however the memory which I set it as 3 bytes can be an integer. In theory, it must not work, must it?

int *p;
p=(int *)malloc(3);

It works but it must not. Can you explain it?

Rio Gábor says:

You should do them in c++

Biprodip Sanyashi says:

What is the exactly role of fflush(stdin) function in this program?

rukkumani n says:

why are u using pointer here
int *p
p=(int *)mallocof(sizeof(int));
y are u using pointer *p here y we cannot use ordinary variable;

Maulin Shah says:

Hello anil sir,

when i do this program i find an error for malloc() and free(). It shows that they should have prototype… so what are the solution for that..

saipravallika polukonda says:

hello ur way of teaching is awesum sir well in this tutorial u said that malloc() returns address of first byte of alloacated memory but u used void there how it gonna returns den?

dev reddy says:

can anyone explain me clearly why is fflush(stdin) is used or any thing is appreciated?

ls p says:

pointer variable can only hold the address .right?
i dont understand ( *p=20;),
please anyone explain

Zigallo Dee says:

Subtitles please, ALWAYS USE SUBTITLES… please ;-( ;-( ;-( ;-(

NoPTic S says:

Anil, i wanted to ask you a question about pointers,
 int *x = 15;
why does it crash?
and why when i am doing that it doesnt?
 int *x = 15;

what extacly does x represent without the * operator?

aakash singh says:

I can’t understand one thing that (int*)malloc(sizeof (int)); returns address. But we are using (int*) shouldn’t it returns value to p instead of address . Or (int*) has no effect on (int*)malloc(sizeof (int));.
Please some body help i’m really confused.

Pratibha Goenka says:

These videos were of great help…all the concepts are explained in a very crisp and explicit way…thank you..:)

 Write a comment


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!