 Hello friends, I am Sanjay Gupta. In this video I am going to demonstrate you what is the difference between malloc and calloc functions available for dynamic memory location in C programming. So first I will be demonstrating the use of malloc, then I will be comparing it with calloc so that you can understand the difference. Before starting, you can note my information. You can connect with me by following these details which are available in front of you. You can open my YouTube channel by searching my name in YouTube search that is Sanjay Gupta. My channel will be available there. You can open it. Here various programming related playlists are available. You can improve your programming skills by watching these videos which are available in different playlists. You can follow my YouTube channel by subscribing it by clicking on this subscribe button. Do subscribe my YouTube channel so that you can follow me. Now I am going to implement first malloc function. Then I will be implementing calloc. So for these functions, I have to include two header files. First is stdio.h and then stdlib.h. Now I am going to define main function here. First I have to declare a pointer p then n and then i variable. Now I have to receive size of memory blocks from user. So I am going to print the message enter size on console then to receive that size from user I am writing scanf. So scanf will read that size and that will be stored inside n variable. Now for memory location, I am calling first malloc. So this is the implementation of malloc function and this is for dynamic memory allocation. So malloc is function which I have called here I have passed n into size of n. So n is number of blocks and size of n means size of each block which will be allocated through malloc. So this multiplication value will be passed in malloc. So malloc will create a memory block whose address or you can say base address will be returned. That will be typecasted into integer pointer through this return type and then that will be stored inside p. So p will be containing base address of the allocated memory block. Now malloc after allocation of memory fills garbage values in each block that is allocated through it. So now I am using printf statement first to display the message elements are so this message will be displayed on console. Now with the help of this loop, I am going to display the elements that will be allocated. Sorry, I will be displaying displaying the memory blocks which is allocated through malloc. So each memory block will be containing garbage value. So that will be displayed for that purpose. I am using printf function and notation asterisk p plus I so p is containing base address. I have added I into it so that it can move to different different locations available in that memory block and asterisk will be de referencing each block so that value can be displayed on console. And after this for loop I can call free function. So free is for dynamic memory de allocation and then return zero. So now I am going to execute this code. It is asking size. So I am entering seven. You can see the output. It is showing garbage values on console seven times only because seven blocks are created. So this is the use of malloc. Now I can convert it into caloc. So instead of malloc, I am using caloc and in caloc, we have to pass two arguments and then comma size of it. So first in malloc, it was only one argument with the help of multiplication sign. Now in caloc, you have to pass two arguments and rest of the code will remain same. But caloc automatically initializes zero in each block of that memory block. Now I am again executing this code. Again, I am entering seven is size. You can see the output. All blocks are printing zero as output. So friends, this is the difference between malloc and caloc. Whenever you use malloc, all blocks filled with garbage value. But in case of caloc, all blocks fills with zero value. So this way, I hope you have understood the difference between caloc and malloc. And also I have used free function to free the dynamically allocated memory so that it can be used by any other application after get freed. So this is all about caloc and malloc. If you want to watch more programming related videos, you can follow or subscribe my YouTube channel. That is Sanjay Gupta underscore tech school. You can download my programming app Techimus that is available on Google Play. Thank you for watching this video.