 Hello friends, I am Sanjay Gopka. I welcome you on Sanjay Gopka Tech School. In this video, I am going to explain how you can pass string into a function with the help of pointer. Before start, if you go to description of this video, you will find various links related to seed language playlist. Those are available on my YouTube channel. So you can follow them if you want to learn seed programming. Now coming on to this topic. So first of all, I am going to declare a function. Then I will be implementing main function and then the definition of user defined function. So this is the declaration of function. So here you can see name of function is length. So we are going to calculate how many characters are available in a string by passing that string into function with the help of pointer. So here you can see this parameter type is character pointer. So I will be passing character array into a function and that character array will be received to a pointer. So that's why its declaration is containing character pointer. And the length which I am going to calculate will be, it comes from integer. So that's why you can see that type of this function is indeed. Now after this declaration, I am writing main function. Then I am going to declare a string and let's say I am writing India. So sorry. So this way I am initializing this string with the value of India. So we need to use name of character array. Then square bracket and equals to time and insert double quotes to put any character collection. So these character collection will be stored inside this character array. Now I am going to declare integer variable. So let's say its name is L. So it will be receiving the return or calculate length. Then I am going to call this function and passing string into it. So here I am passing SPR that is character array as an argument. So this is input for this length function. And this is the calling statement of length function. And after completion of the process of this length function, the return of the variable will be available to this L variable. So after this, I can write print as length equals to percent D and here I can print L and then I can close main function. Here you can notice I have finished writing this character array myself. I didn't receive anything from the user. So in your environment if you want to read values from user, so you can remove this double quotes India from here. And after this character array declaration to the length print as can a function so that you can read values from the user. So these are optional things if you want to read values from the method as well. If you want to give values by yourself then you can remove those critters and you can write on the statement like this. So here you can see main function is completed. Now I am going to write definition of this length function. So in length and here I am writing character pointer and then opening the categories. So this SCR will be passed into this character pointer and here I am naming this character pointer as P. So P will be having the base address of this character. So how it will be working? So I first I am writing the complete code then with the help of example I will be explaining you how this P pointer can access all the elements of this character array that is available in SCR. So here I am declaring two variables or sorry one variable that is in L and I am initializing it with U so it will be calculating length. Then I am writing why SCR is P not equal to none. So I hope you know whenever we create any string. So after assigning values to that string at the end of that string none character stores automatically. So here you can see I am checking this condition if S-P is not equal to none it means we have a valid character. But if S-P is equal to none it means we are at the end of string so that we can terminate the loop. So that's why this condition is available here and inside this condition I am just implementing value of I by Y and incrementing value of P by Y and closing this. So length variable is implemented and P pointer is also implemented and after termination of this loop I am going to return value of L. So this value will be returned here and then output will be distributed. So this is the code that will work by passing string into function using pointer. Now I am going to tell you how it will be working. So let's say here I am creating character array. So interest having India as input. This is null character. These are indexes. So these are values. These are indexes and here I am writing addresses. So I hope you know whenever we declare any character variable of character array. So character variable occupies one byte and character array if we declare character array so each location of that character array also occupies one byte of memory. So that's why you can see each block is having only one address. 101 is for this, 102 is for this, 103 for this location and so on. And remember that I have assumed these addresses. These are not actual addresses. So whenever you will be implementing this in your laptop or in your desktop. So these addresses can differ. So I am assuming these addresses. India I have indexes here, that's why I am mentioning and indexes always start from here so that's why I am using them. Now we have a pointer P which is declared here. So whenever we call any function, so control automatically transfers to its definition. So SDR will be passed into this P and I hope you know whenever we use name of any array. So name of array automatically provides its base address. So this is an array whose name is SDR and if you are passing SDR into P pointer, which means SDR will provide its base address to the pointer automatically. So base address of this SDR is 101. Base address means the address of the location and that will be available into P pointer. And pointer, I hope you all know pointer. So pointer is a variable which can store address of any location. And through that stored address we can access value of the location. So through P we can access the value which is stored inside 101 address. And for that I am using this SDR. So now I am going to get this loop. So here you can see SDR is mentioned. So SDR means if I write meaning of SDR, so SDR means value at address. So what is the address 101? So SDR is P means SDR is 101. It means value at 101. So 101 is having capital I. So capital I not equals to null. So condition is 2. I is not equals to null. So L will be incremented by 1 and P will be incremented. So now again you need to understand how pointer increments. So P is having 101 and we are incrementing it by 1. So pointer is of type character. So if pointer type is character then whenever you increase that pointer, so it will automatically increase the address which is stored inside it by 1. Because each character variable occupies one byte of time. So whenever we increase this P pointer, so it will increase the value. Or you can say the address which is stored inside it by 1. So 101 will become 102. If we are implementing the program for integer array. So for 16 bit compiler it will increase addresses by 2. And for 32 bit compilers it will increase addresses by 4. So as per the data type, the addresses which are stored in pointer increases. So now P is pointing to 102. So if again we re-reference it as per speed. So right now P is pointing to 102. So as per speed, value address. So value at 102 is M and M is not equal to null. So again quantization is true. So L will be incremented and P will be incremented. So this way P will now point to 103, then 104, 105, 106. When P will be pointing to 106, then this quantization will become false. And whatever value will be abbreviated to L that will be returned into this L variable. And through this printer, the length will be printed off. Output speed. So this way I hope you understood how we can pass character arrays into function. And inside that function, we can receive base address of the character array into a pointer. And through that pointer, we can iterate the complete string for character array. Till this null character. So I hope you understood how we can pass strings into function with the help of pointers. And if you want to watch more or see programming related videos. So you can go to the description of this video where you can find links of various playlists. So you can follow that and I hope you understood whatever I explained in this video. Thank you for watching this video.