 Hello friends. I am Sanjay Gupta. In this video, I am going to demonstrate you how you can read and print string using dynamic memory allocation in C programming. 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 on first page of YouTube. You can open it where various programming related videos and playlists are available. You can watch them if you want to improve your programming skills. You can also download my programming app Takimiz that is available on Google Play. Now I am going to implement solution of this problem in front. First of all, I am going to include a header file that is stdio.h. Now I am including another header file that is stdlib.h. Now I am defining main function. First I am declaring a variable integer type and then I am declaring a character pointer. So string is basically a character array. So for a dynamic memory location, I have to use a character pointer so that character array can be allocated using malloc or calloc. Now through printf, I am going to display the message enter size of string. That how many character you want to store that size will be received through scanf inside n variable. Now I am going to call malloc function so that desired memory will be allocated for this pointer p. So this way dynamic memory will be allocated. So here malloc will be allocating n into size of care blocks and the returned address will be typecasted into character pointer. And that will be stored inside p pointer. Now through p pointer, I can receive the input from user. So printf message will be displaying enter string. Now to receive string, I am using gattus and then p pointer. So the entered character will be stored at different addresses that is pointed through p. Now I can print the entered string on console using this printf %s and then p. Now for dynamic memory deallocation, I am calling free and then return 0. So this way I have implemented the complete code in front of you. Here dynamic memory is allocated for character array. Then through gattus, I have read all the content of string and through printf, I am printed. I have printed back those entered values on console. Now I am executing this code. I am entering size 6 because I want to enter India as input. But you can see it is not asking for the input. It is just showing the output. So in C programming, whenever we read integers and after integers, we read characters. Then buffer memory automatically does not clear. So for that purpose, I have to call a function f flush and I have to pass an argument std in standard input. So this will clear the standard input buffer memory so that desired input can be received from user. Again I am executing this code. I am entering 6 as input. So this time it is asking the string from user. So size is 6 and input is 5. 6 because null will be stored automatically at the end. So you can see I have entered India. So it is showing you entered equals to India. So this way the program is working properly. So don't forget to use f plus function while reading integers and characters in a C program. So it is required to clean the buffer memory that is responsible for reading the input from the user. So this way I have implemented the program which is reading and printing string using dynamic memory location in C program. So I hope you have understood the code well how you can do this operation. If you want to watch more programming related videos, you can search my name in YouTube that is Sanjay Gupta. My channel will be available on first page of the YouTube. You can watch various programming related videos there. Thank you for watching this video.