 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can copy or string into another using dynamic memory allocation. Before starting, you can note how you can search my YouTube channel. You can type my name Sanjay Gupta in YouTube search bar. My channel will be available there on first page of the YouTube. You can have or you can find out various programming related videos and playlists there. You can also download my programming app Techimus which is available on Google Play. Now I am going to implement solution of this problem. So first time including a header file that is stdio.h. Another header file stdlib.h. Now I am defining main function. Inside main function I am going to declare variable n then two character pointers p1 and p2 and I am declaring two integer variables n1 and n2 because I have to read size twice for these two strings and one more variable that is i. Now I am going to display the message enter size of first string that size will be received through scanf and will be stored inside n1 variable. Now for memory allocation, I am going to call malloc function inside malloc. I am passing n1 into size of care. So this statement is responsible for dynamic memory allocation. Allocated memories base address will be typecasted into character pointer and that will be stored inside p1. Now again I am going to display the message enter size of second string. This will be received through scanf and will be stored inside n2. Now for p2 again I am calling malloc function. So n2 into size of care memory will be allocated. So I have successfully allocated dynamic memory for p1 and p2 pointer. Now I can read a string from user. So I am going to display a message enter string. Before reading I have to call f flush because I want to clean the buffer memory so that I can read characters just after reading the integers. So here I am passing p1 into getters function. So the string will be stored inside p1 pointer. Now to p1 pointer I have to copy this string into p1. So for that purpose I am implementing while loop where p1 plus i sorry s-risk p1 plus i not equals to null. This condition is available. So this condition is checking whether the value which is stored at p1 plus i location is equals to null or not. So if it is not equals to null then only I can assign values that are stored at p1 plus i location into p2 plus i location. So this way value of p1 plus i will be stored inside p2 plus i locations and then I can increase value of i to 1. So this way this loop will be repeated and if condition is false then this loop will be terminated. After termination I have to assign null because null will not be copied. When null will be occurring here in this while loop, loop will be terminated. So in p2 pointer I have to assign null also. So now I can print output on output screen. So copy string equals to percent s and then p2. So with the help of p2 pointer the copied string will be displayed on console. Then I can call free p1 and free p2. So both pointers will be releasing their allocated memory so that it can be used to any other application and then return zero. So this way I have implemented the complete code in front of you. Now I am going to execute this code. So I have to enter the size of first string. I am entering six size of second string. I am entering six. It is asking for string. I have entered India. So you can see the output copied string is also India. So this way the program is working properly. I have entered the input in p1 pointer and I have displayed the output through p2 pointer. So both are printing same results. It means p1 pointer has copied its all contents into p2 pointer and through p2 I can display all the contents of a string on output screen. So this way I have implemented copy of a string into another using dynamic memory location. I hope you have understood the logic well. If you want to watch more programming related videos you can type sanjay gupta in youtube search bar. My channel will be available there where you can find out various programming related videos. Thank you for watching this video.