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 http://www.LearningLad.com for more free computer programming video tutorials.
Learn Programming in HINDI at our youtube channel
http://www.youtube.com/user/LearningLadHindi
Catch us on Social Media
http://www.facebook.com/LearningLad
http://www.google.com/+LearningLad
http://www.twitter.com/LearningLadEdu
Amazon Auto Links: No products found.
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?
Thank you for showing us this in C. Well-explained video.
what does fflush() do ?
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?..
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);
*p=10;
printf(“%d”,*p);
It works but it must not. Can you explain it?
You should do them in c++
What is the exactly role of fflush(stdin) function in this program?
why are u using pointer here
main()
{
int *p
p=(int *)mallocof(sizeof(int));
y are u using pointer *p here y we cannot use ordinary variable;
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..
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?
can anyone explain me clearly why is fflush(stdin) is used or any thing is appreciated?
pointer variable can only hold the address .right?
i dont understand ( *p=20;),
please anyone explain
Subtitles please, ALWAYS USE SUBTITLES… please ;-( ;-( ;-( ;-(
Anil, i wanted to ask you a question about pointers,
int *x = 15;
printf(“%d”,*x);
why does it crash?
and why when i am doing that it doesnt?
int *x = 15;
printf(“%d”,x);
what extacly does x represent without the * operator?
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.
These videos were of great help…all the concepts are explained in a very crisp and explicit way…thank you..:)