 Hello friends. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to explain how you can reuse a user defined function. So reusing a function is basically a benefit of defining user defined functions. So you might have implemented functions in C language, but you might thought like what is the benefit of defining user defined function because we are just separating logic from main function to any other function. So we can implement that into main function as well. But in this video or after watching this video, you will get to know what is the benefit of implementing user defined function or how we can reuse that. Right. So for explanation purpose, I'm going to take an example of tutorial program. So we all know that function have three parts declaration, calling and definition. So let's declare a function. So here you can see this is the written type of function, then it is name of function and this is parameter type. So that function will be receiving an integer as input and it will be returning as an integer as output. So this first line is declaration of this user defined function. Now after this, I am defining main function. So let's say I have one variable and one whose value is five and other variable is F. So I'm going to calculate factorial factorial of this and one variable and the result will be stored inside F. So here I'm writing this F equals to back and one. So this statement is function call. And the result will be available into F. So it will be printed on output screen. So I'm writing factorial equals to F. So, so this way I implemented this main function right now after implementing this main function I'm going to write the definition. So, so I'm writing this in fact, then in 10. Right. And this is I will give them at this one, then I'm applying a volume, which will repeat and times it will calculate factorial after completion of this loop. I can return value of F to main function. So this way I hope you implemented functions and you might have thought why to write this logic separately. We can merge this into main function as well. So by implementing this function approach, we are stretching a line of codes. Right. So now I'm going to resolve your doubt, like, what is the benefit of implementing user defined function. So let's understand this first. So after falling, but don't always transfers to its definition. So value of this and one will be part to this end variable and based on this and bacteria will be available into F and that F will be returned back to this F. So this way this function works. Right. Now, after calculating factorial of F, I want to calculate factorial of one more variable. Right. So let's say I have another variable and one has six and F one that will be storing its result. So what I have to do if I don't have any user defined function, then inside main function, I need to implement for loop twice. Right. One for five and one for six. So if I want to calculate factorial of more than one numbers, I need to implement for loop again and again into main function. But if you have separate function, if you have separate function, which is particularly calculating factorial of any number, then in that case, we need to implement for loop only once and then you just need to call that user defined function again and again. So now you will see how I will be calling this function again so that I can calculate factorial of six as well. So after this printf, I'm writing F one equals to fact of, sorry, here I am writing N two. So, mistakenly, I mentioned and one here. So I'm going to have a pipe which, which we already calculated. So here it is and two whose value is six. So here I'm passing and two as an argument and the result will be available into F one and I'm writing printf factorial equals to personally and F one and then I'm closing me. So here you can see this definition is available only once definition is available only once but calling statement is available points. So same function definition and calling more than one time without implementing or without repeating the logic. So this is the benefit of user defined function. You need to implement logic only once just you need to call it again and again so that you can perform that operation. Any number of time. So let's say this factorial function is having 50 lines of code. So by using this function you reduce your 50 line because if you have implemented these 50 lines. Two times into main function. So your code will be having 100 but here you can see we implemented it once and we call it more than one time. So this 50 I took for example purpose. So in case of large user defined functions. This is better to implement user defined function approach so that logic will be implemented once and you can call it again and again. So first this call will be happen and one will be passed into and it will be calculated F will be returned here. It will be printed. Then I mean this function will be called now and two will be passed into and so here you can use any variable if you're passing value and one and we'll receive value of and one. If you are passing value of and two and will be receiving value of and then this return F will return value into F1. So we can use different names while passing arguments or while returning value. So don't remember like we need to use same names. We can have different names as well that will work correctly. So here you can see F1 will be printed. So this way definition we have implemented once calling be done twice and declaration once. So this way you can increase this number but declaration and definition will be done once and calling you can do any number of times. So this was the usability of user defined function. So I hope this way by watching this video you understood the main advantage of user defined function. So if you have one user defined function then that logic can be called again and again without writing whole logic again. So this is the major benefit of using user defined function. So I hope you understood whatever I explained in this video. If you want to watch more programming related videos go to description and see various playlist related to C language. So you can follow C related videos there. Thank you for watching this video.