54 - FUNCTIONS - C PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome to our Channel so in this session let us have a look on one more concept of a sitting glitch that is functions so before going to that what is an importance of functions so mainly these functions are used to reduce the complexity of the program and in order to have a reusability property as we know a software developer and they can be reused in a number of projects so for that purpose we will create these functions so that means concern a large problem and they can post a large problem into subproblems and each sub problem will be developed independently and this sub problem we call it as functions so main problem is divided into subproblems subprogram and all these sub programs will be developed independently and finally we have to integrate we have to litigate and we will get the solution for this main problem so based upon the functionality we have to divide the main problem into sub programs and each sub program will be developed independently and finally we have to collaborate or integrate the solutions of all the sub programs to get the main solution so this process is we will do this process in order to reduce the velocity and to achieve the reusability property and also to make the process of debugging easier the process of debugging easier as we know that the debugging process is so identifying the error and resolving the effort so that we call it as debugging process and mainly by using this one we make the debugging process easier so this sub programs are called functions or modules motors so we can call them as sub programs or functions or modules so finally this programming we we can call it as modular programming we call it as a modular program so because if you deal with complete murders and this process is known as divide and conquer depending concurrent method that means we are dividing the large problem into different subproblems and we are getting the solution of all the subproblems and integrating all the subproblems we'll get the final solution so this process we call it a 30 minute conga and this programming this type of programming we'll call it is a modular programming and this individual sub programs we call it is a functions for motors now what are the types of functions how many types of functions so mainly there are two types of functions what is user-defined functions other one is predefined functions user-defined functions at a predefined functions so as the name indicates user-defined functions are the functions which are returned by the user so those are the sub programs which are returned by the user and here these predefined functions are also a functions or a sub programs but the logic will be encrypted by the company so for example let us have a look for example for these three different functions so so far we have seen different pre different functions let us say printf so it is also a predefined function so we are not writing any code for printing the text or any value on the display screen just we are using this printf function so that the complete data is displayed on the screen and similarly scanf so we have mount writing any code we are just using the function similarly our function sqrt function strg course osanic function and function so all these functions we are not writing any code just we are making use of those functions so these function are all called three different functions in order to execute these three different functions we have to include the cost for the end of X so for example this printf and scanf functions we have to include standard input/output H header pipe so complete logic for this pretty different scanf function will be included in this everyone assuming the power function square root cause and pan so these functions the logic will be presently included in math dot H so we if you fail to improve this macro th this function will not work so here would do is use a different function means we have to create a program that thinks complete logic must be returned by the user itself so these are the predefined functions and these are the user-defined functions so let us see this user-defined function so similarly as the pre different function having names so this use a different function should also have a specific name and that name should be given by the user so we have to follow the rules while giving the function name and already we have seen the rules to be followed by creating a variable name so all the rules are applicable for giving the function name also so we have to follow the same rules which were following by create a variable name to create a function name so first and foremost rule is we should the the name should not be matched with any one of the technical keywords and the maximum length must be 32 characters and no special symbols except the underscore is an algorithm function name so all these rules we are already seen in the variables while variable so here also we have to you follow the same rules so in this we have to use a function name and similar to the variables here also function is having one correct and a similar to all variable data type here the function is having one greater and a greater thing or we can say this and this return type may be any one of the four fundamental elements that means it may be is an indigent character fruit or edible so for every function there must be a reckoning and one more thing so our execution always starts from the main function and it will execute only the main block so in order to execute this user-defined function we have to give a reference of this user-defined function in the main function and like the variables we have so far the variables we are declaring all the variables before using them in the program similarly in the functions also we have to declare every function which before using those functions in the program so three constants must be remembered while implementing the function first one is function declaration next function call next one function definition so by the blue building any use a different function will have to follow these three concepts first function regulation from shall call and function definition coming to this function declaration like the variables we are declaring a variables which we are going to be used in the program at the beginning itself similarly we also we should declare a function before using them in the program so here where we have to declare a function so this declaration must be done above the main function and above the main function and what are the elements to be used for declaring the function first we have to write the return type returning for my function name parents is open variable one data type variable two and so on so this is the syntax this is the syntax for function declaration so before using the user different function we have to detail that particular function so in the declaration we have to mention the return type functioning and all the parameters we call these as parameters or arguments parameters or arguments so in the function definition itself one the function declaration itself we have to specify the return type and one of the arguments we are giving as inputs to the particular function these parameters are our arguments are the inputs given to the particular function so these are optional so we can specify the parameters in the function definition or directly we can use in the user different functions so coming to this function call or simply we can say we can write the syntax has written type function name and just hide the data type small glory of writing the variables data type data type and etc so how many variables we are giving as arguments so that many database will have to specify in the function declaration so the function declaration must be done just above the main function next coming to this function form so as it said that the function the user different box the user different function is the logic of a sub program written by the user so where we have to write this watch so this use different program this user different functions should be written just outside the main module so just refer the first videos that is a structure of AC program then we have mentioned the main function and then user-defined functions so just I would say the main function we have to write the user different functions so we can write this user-defined function above the main function or through the main function anywhere else but outside the main function we have to write outside the main function so in order to execute that the particular function use a different function we have to include a reference of that particular user-defined function in inside the main function because our compiler executes only the main function so the compiler will search for main function and the execution always starts from the main function so in order to execute this user-defined function we have to write a reference of this function definition the user-defined function inside the main function so that reference name we call it as function call so whenever the control reaches to this function called automatically the control will redirect it to the user-defined function in the program and all the program will be executed so all the statements will be exhibited so whenever the control reaches the closer braces of user-defined function again the control will get back to its original position in the main function so where for where the control who came to the user-defined function so at that position the control will get back and the normal execution sequence and sequential execution will starts so this function path is a reference to the actual user-defined function logic of user function in the main function so this function call should be written inside the main function so here we have to write inside the main point inside the main function so what are the elements to get it out there so the here also the syntax is we need to write the return type directly we can write the function name formed by list of parameters list of parameters or arguments simply we can write it here so this is a function call which should be written in the main function main and coming to the third concept that is function definition this is the actual logic way we have to write the user different function so that means what about the statements you should be execute that all those statements should be written in the function definition so this function should definition should be written just outside the main function so in outside the main function we have to write outside the main and here what are the elements to be written again we have to so here in this two we have to place the semicolons and the end of the line so return function function then date of the variables and semicolon and function name or the list of parable for our moments in Senko here we have to write the user defined function actual logic of the program so what's the syntax here again you have to write the return type the function name list of parameters over the place local variable declarations so we have to if if our program makes any local variables then we can write here our variable declarations and then executable statements so that makes logic of our program and then return function so greater so these are the elements in the these are the elements should be written in the function definition so return type function a list of parameters no a variable declaration executable statements and so every function every user different function will return back to its parent function so that's why we have to write this and if this written may may be an empty return or it may return any value to its parent function so here the empty return if it is an empty return we have to specify here the run return type as a void so if the function use a different function doesn't return any value to the main function or its parent function we should specify here the return type as Y in if our user different function returns some value to its main function or a parent function we have to specify here the return type as a data type that it is returning to the main function that means if this value is returned back to its parent function we have to write here return type as integer if the return is this user-defined function returns a float value to the main function or sub function parent function then we have to specify this return tech as a float so that's why this is recommend may be anyone among different fundamental determines so while implementing the functions we have to specify and we have to follow all these three concepts first function declaration function call and the function definition so like variable we have to declare a function before using that and then our execution how they starts from the main function so we have to write the left function definition in the function main and the function definitions the actual logic of it saluton and here these are called parameters or arguments next here the parameters are of two types one is actual parameters another one is for the parameters parameters of today's actual and formal parameters so which parameters hukala is actual and which parameters we call a super actual parameters are the parameters which we are writing in the function call so parameters which are written in the function call we call them as actual parameters formal parameters so the parameters which we are very return which are written in the function definition after the formal parameters two types of parameters actual parameters and the formal parameters next there is a two more technologies that is a calling function and third function what would function recorded as a calling function which function we call it as a current function so commonly function means in which we are written we are writing the function call a function which is having function part the function which is having a function call comes out of the calling function and the function definition in the function definition will call it as a column function calling function called function formal parameters and the actual parameters now let us look at working on functions so we can clear them so if the main function is having a sub function so the control the compiler will always starts its execution from main function so we'll execute the statements of main function sequentially whenever the control reaches this function call automatically the control will search for this function name outside the main function if it forms so automatically the control move all through this function definition so whenever again starts executing sequential in this user-defined function whenever it reaches this curvy brace again it will get back to is the next statements and the main point it will return back to its parent function so compulsory every user-defined function will return back to its parent function after executing the statements of use of different function so here the question is the return may be empty return or a value return so it may return empty that means without any value or it may return to respect with again so let us have an example so that you can clearly understood this concept claim so let us take a simple example of addition of two numbers using functions so that we can see all these concepts so this is a simple program for addition adding two numbers using functions so here we have to follow the three concepts as I said it in the function declaration function without following the same order function declaration function call and function definition and we must be careful while writing the list of parameters so the count that means the number of is the number of parameters should be same in function definition function declaration function call and function definition so here so this is the function declaration so we have to write this we have to write this declaration above the main function so I have written this integer return 10 so that that indicates this function called indicates the function name and they accept two inputs with integer data type and raters and integer result to the parent function so in the main function this is a function declaration this is these are the parameters that means two parameters so I didn't mention any variables just I have mentioned the data rules and this is the return name and here I have taken two variables input variables that have declared two input variables and one output variable and how to take in the input for both the input variables a and B by using the scanf function and i have initialized the result with a function call so sum is equal to add a comma B so this is a function call so I have to write the difference of this function definition in the function call that means in the function definition itself we are writing the logic actual logic will be the definition so you have to execute this function definition we have to write the reference of this function definition in the main function so that we call it is a function here also we have to write the same function name and the same number of parameters here we have written in the Declaration two parameters so here also I have written two values a and B so I am passing the values of a and B to the user different function with a functioning and and the result is stored in some so the result of this function must be assigned will be assigned to the variable Sun so the control figures line the line and whenever it reaches this function call automatically the control will move on to this function definition so it will search for this function name in the program and ideally the control goes to the function definition here also the net contract in as I mentioned in the declaration so we must be careful by writing the second concern parameters the number of parameters so that must be equally to both the Declaration and a definition so returning ad is a function name and parameters two parameters x and y so this is a function definition this is the function definition and here we have written one more variable dollar variable that is a result and we are writing the logic of addition result is equal to University and we are returning the value to the main function that means main function is which function we have all that to that function we have to send back the value that means result we are returning the result so here the result is calculated and reason whenever the control introduces return result automatically the they go back to his normal sequential execution to its spirit function so here parent function and a child function so parent function is a witch function we are writing the function for that function we call it a parent function that means a calling function and which function we are calling is called quadrant so as I said there are two different parameters so in the function call these parameters are called actual parameters the parameters of the function call we call it as an actual parameters and the parameters in the function definition or called formal parameters so here the value of J and B will be copied into the formal parameters that means the first variable the first actual parameter the value of first actual parameter will be assigned to the variable of first formal and similarly the second value of actual parameter will be assigned to the second variable of formal parameters so likewise in the minion order it will be a same that means the compy will be computed for actual parameters will be assigned to the formal parameters so be careful that I am saying that just remember I am saying that copy of values will be assigned to the formal parameter so these values will not change and these are the new values as I said that these are the local variables here U and P here also we can write the a and B because both are different as their local variables so the local variables are away only in the particular function where we are declaring those variables here may be a declared in the main so yeah and big values are alive in the only main function similarly here also we can write the same variable so there is no problem so he and me so we have two more variables that is X & Y so that means a value may be sent to the X and B value will be assigned to white and the result is calculated and the result will be great and back to the calling function and correct function so the sum is the result will be assigned to the sum and in this next statement I have printed them somewhere so some will be printed so in the same way the functions will be incremented so every function so we must be careful while writing this function every function will return to its calling function so that return may be empty written or a gravimeter so here the way it is a value return and come to this empty return so I will invite the empty return also so that you can clearly understood so I am not mentioning in assigning the result of sub function to any variable so I am just writing the add a B so it does not return anything so mean so if we have to write the return type as my dad ETH term oh my baby so here is a second to X Y D is a zani through one so here in result see in the result result is equal to a and B it gets my printf sum is equal to percentage B isn't so here I am just calling the function and the main function so that the control will move to the function definition and here I have calculated the result and in the user-defined function itself I am printing the result so I am not returning any value to the main function so whenever the control reaches this closure brace it will again go to here so as there is a no statements main function will be closed executed so if you can see this that means H will be executed so in the previous program the user-defined function have returned the result to the column function in this program the result is printed in the user different function itself so that empty return is there to the main function so the return may be empty enter or evaluator so this is a simple example for all the function concepts hope you understood this and here let us stop here in the next session I will explain you the various categories of function definitions and the parameter passing techniques and thank you if you like my videos share my videos with your friends and if you are having any doubts regarding these functions or any in concept in the C language feel free to post your notes in the comment section so that I will definitely I will try to clarify your doubts regularly and thanks for the resisting my video and thank you
Info
Channel: Sundeep Saradhi Kanthety
Views: 301,735
Rating: 4.9050236 out of 5
Keywords: sundeep, saradhi, kanthety, c language, c programming, cp, computer, computer programming, loops, Functions, function declaration, function call, function definition, formal parameters, actual parameters, calling function, called functions, function basics, subprograms, modules, modular programming, return type, function name, arguments, return, addition using functions, c training, programming c
Id: TEHA_IwNk34
Channel Id: undefined
Length: 37min 3sec (2223 seconds)
Published: Wed Oct 11 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.