 Hello, welcome to the session user function in C to find length of string. At the end of this session, the student will be able to write a C program to find length of string. First, we will see string declaration. String is nothing but an array of characters. In the string declaration, there are many types. This is the first method. We are having address that is the string will be stored in the address and it is declared by character. So array of address that is the in that we can store with single code TEXAS when we want to store Texas. The string total will be Texas in the address and at the end we will be including slash 0 that is the null character. So that will indicate that is the end of that particular string. In the second method, we will be having the same definition character address of array. Then in this instead of the single code, we are having this double code TEXAS. So it will be store the string in the array, but in this the slash 0 that is null will be automatically inserted at the end of the string. No need to add the slash 0 or null character. What is this null character we are adding to this? So null represent the end of the string and it is also referred as a string terminator or null character. Then we will see two types of reading and writing the string. In this first, we will see the printf and scanf. In the next, we will see gates and putes with the help of we can read the string and write the string. Scanf enter your name, this will be read your string. So how it is reading? Here you can see that scanf. It is a normal scanf where we are using for integer d float f first character we are having c, but here we are having s that is for the string. So it will read name as a string, then once it read the name from the user we will print it with the help of again dollar percentage s, then name return. So it will be first your scanning that value that is enter your name rohe then it will be print your name rohe. So in the next method we are having gates and putes or the name gates name. Now here instead of scanf percentage s we are using gates. Then with the help of putes we will be writing the string. So enter your name walchen and where when we are writing putes name it will be again giving the print as a print walchen length program. C string length program is to find out the length of a string. For example here we are given c programming we need to find out the length. So here it will be total 13 character including space. Now in this case string length c program we are having one library function for measuring this length of any string that is strlen. Now how it works first we will see then we will write our own program. Here we are including stdio.h including string.h here I am having one string that is going to be stored into the a. So that is having a hundred space in the memory. So integer length we will measure the length then we will print first enter a string to calculate its length. Then we are getting that a and we are finding length is equal to strlen a then it will be print the length of string. Find without using strlen which is a built in function then we will create user function to find out. We will scan all the character in this what we will do the string is there we will scan all the characters in the string one by one and the scanning will be end till we are not getting the null character it will be continue that then we will increment the counter as we are scanning the characters. Once the null character is found the counter will be equal to the length of string. So this is the simple first program that is the again we are stored s then c is equal to counter is equal to 0 first inputting string any string with the help of gate s we can read the any string with the help of gate s. Now here our logic is there while s of c is not equal to null we are going to scan that and we are counter is incrementing one by one and finally once we are getting this null character it will be come out from this array and that will print the length of the string c here it is shown output. So first input a string here we are inputting WIT then here inside the array it will be showing that WIT it is going to be stored in this way with the null character and we are scanning one by one and it is giving length 3. The same user function we can write with the using function here we are used a simple in the same main program we are writing that then we are using the function and writing the program. Now in this case again we are having this function we are declared the function integer as it is returning us a integer value that is the length of string and the name of the function is string underscore length and it is passing the string which is nothing but the string array string is character array in integer main again we are declared this any string counter inputting the string with the gate as then we are writing the length of the string by calling this function string underscore length here function to find string length. So after calling we will be here integer string length character array then counter is 0 then while null is we are not getting null we are counting we are scanning and counting that particular string characters and at the end when we are having the null we are returning that counter C which will be printed here. Then C program to find out length of string using recursion though this main program will be same we are having one function to find out the length string underscore length here we are giving or passing the pointer character pointer when our string will be star then we are getting that particular string and then we are sending this to the function. So here you can see this we are having this function in this while our character is not null we are incrementing counter C and if it is not null it is calling this string underscore length s plus 1 the same function again so that is why it is called as a recursion the function is calling own that is the recursion here we are using the same we are going to check the length of any string with the help of pointer. Now here integer string underscore length here I am giving the function only this is the function we are wrote here with the help of pointer this pointer is passed from the main program as we have seen the in the main program we are passing the array character array and the start of that string pointer here counter is equal to 0 while our pointer is not getting that particular null character we are incrementing the counter and then we are returning the C. Now pause your video read this question and try to answer this what is the question find out the output of given program and rewrite the program to find out the length of string str1 and str2. Now we need to print here n1 n2 now here we are finding n1 is equal to 10 and n2 is equal to 9 why it happens because in str1 and str2 in both cases we are having same string but as I told you in the first slide that is when we are having double code the automatically null character is going to be append to that string at the end of that particular string. So it will be calculated str1 will be 10 and here str2 will be 9. So this is the size of str1 is 10 and size of str2 is 9 when an array is initialized with the string in double code compiler adds a null character at the end automatically. Thank you.