 Hello friends. I am Sanjay Gupta. In this video I am going to demonstrate you how you can find out length of a string 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. You can open it here. Various programming related videos and playlists are available. You can also download my programming app that is Techimage which is available on Google Play. Now I am going to implement the solution of this problem. So for that purpose, first I am including a header file that is stdio.h. Another header file stdlib.h. Now I am defining the main function. Inside the main function I am declaring a variable that is integer type n, n variable c. C is initialized with 0. Now I am declaring a character pointer that is p. With the help of printf, I am going to display the message enter size of string. To receive that size, I am using scanf. Entered size will be stored inside n variable. Now I have to allocate dynamic memory. So I am calling malloc function. So with this malloc function, memory blocks will be allocated that will be equals to n into size of character. So this memory block will be allocated. malloc will return a base address of that memory location. It will be typecasted into character pointer and then address will be stored inside p pointer. So this block is responsible for dynamic memory allocation. Now I can read the string from user. So this printf will print the message on console or you can say output screen. Now I have to call a function f flush where I am passing std in. So this function will clear the input buffer so that after reading integers, I can properly read characters from user. So now I am calling getters and the entered string will be stored inside p pointer. So p is pointing to the entered string. Now I can I can access or I can implement a loop. And through that loop, I can count how many characters are available in that allocated memory location with the help of p pointer. So for that purpose, I am implementing while loop inside while loop. I am going to implement a condition that is a stress p plus I not equals to null. So p is having base address of the memory location. And here I am going to initialize I with zero and I am declaring I in integer variable declaration. So I is zero. So I will be added into p pointer so that first location can be pointed through this pointer. And through this a stress symbol, I can access the value that is available on that location. So if that value is not equals to null, then I can write C plus plus. So C is a counter variable which will count how many characters are available in a string. Then I plus plus. So I will be incremented by one every time. So P will be added with I and new addresses will be created and those values will be identified with the help of a stress symbol. So it is representing here the referencing scenario. So if P plus I is dereference dereference and it is not equals to null, then only this loop will repeat. Otherwise it will be terminated. So after completion of this loop, I can print the value of C on console that is length equals to percent D and then C. So this way I can print the value of C on output screen. And after printing, I can call free function which will deallocate the dynamically allocated memory. So this is the complete program which will count how many characters are available in a string. And this program is implemented with the help of malloc function that is responsible for dynamic memory allocation. So I am entering size as six and I am entering India as input. So you can see length equals to five. So I have just entered five characters. So it is counting those characters properly. So with this way I have implemented the solution of the problem in front of you with the help of dynamic memory allocation. So you have understood how I have implemented this. If you want to watch more programming related videos, you can search my YouTube channel by my name Sanjay Gupta in YouTube. My channel contains various programming related videos. Thank you for watching this video.