 Hello everyone, today we are going to see the function declaration, function definition and function call in C. At the end of this session, students will be able to declare, define and call the function in a program. In order to make use of a user define function, we need three elements that are related to the functions are function declaration, function definition and function call. Now, first we see the function declaration. Like any variable, a function must also be declared before it's used. Function declaration informs the compiler about the function name, parameters that is accepted and its return type. It is also called as a function prototype. Basically, function declaration consists of return type of the function, function name, parameter list and terminating semicolon. Now, let us see the syntax of function declaration. Initially, we declare the return type followed by function name and the parameter list. Consider a simple example for calculating sum of two integer number. Here we observe how the function is declared. So integer, sum and A and B are declared as return type, function name and the parameter list respectively. Now, first we see the return type. When a function is declared, to perform some sort of calculation or any operation and is expected to provide with some result at the end. In such cases, a return statement is added at the end of the function body. Return type specifies the type of value, either integer, float, character, double. That function is expected to return to the program, which is been called by that function. In case function does not return any value, then the return type would be the void. Now, next we see the function name. Function name is nothing but an identifier and which specifies the name of the function. Now third is the parameter list. The parameter list declares the type and the number of arguments that the function expects when it is called. Also, the parameters in the parameter list receives the arguments values when the function is called. They are often referred as a formal parameter. A parameter is a variable that is used to receive data from outside into the function. A function may or may not have a parameters. Now, let us see an example of how the function is declared. Suppose we want to calculate some of two values of type double using for function. So, first we declare the function. Now, initially we declare double as a return type. Name of the function is declared as a sum which takes the two parameters x and y of type double. It calculates the sum of two values having data type double. Afterwards, we return value calculated by that function sum. Let us consider another situation where return type is void instead of double. Here we observe that return type is void. It means that the function will not return any value and the function name is sum having the two parameters x and y declared with data type double. It will just display the result without any return type. Here the return type is integer. So, this function will return an integer type result. This function receives one integer type value as a input and it calculates the square of given integer number and the return result. So, here the return type is a integer and the name of the function is the square and it takes the only one parameter of integer type to calculate the square of number. After studying the function declaration, can you write the function declaration for calculating the area of circle? Pause this video and think about it. So, here we declare the function declaration for calculating the area of circle. So, here return type is a float. Name of the function is area underscore c and it takes only one parameter of type float. Next, we will see the function definition. Function definition consists with two parts. First is the function header and the function body. Now, first we will see the function. Function header is nothing but just name of the function with its parameter list. After the parameter list, do not use the semicolon as we are not terminating. Instead, we are going to define the function body. Now, next we will see the function body. Function body contains the declaration and the statements necessary to perform the required task. The function body enclosed within the curly braces and it consists of three parts, local variable declaration if required, function statements to perform the task inside the function and a return statement to return the result evaluated by the function. If the return type is void, then no return statement is required. Now, this is a syntax for function definition. Here, this is a function header and this is a function body. Let us write function definition for calculating the square of number. So, for calculating the square of number, we write the function definition. So, first we define the function header. Here, the return type is integer. Name of the function is square and it takes the one parameter of type integer. Then, we open the function body. In function body, first we declare the one local variable result to store the result of the square. After that, we calculate the square of number and that value is stored in the result. Next, we use the return statement to return the value calculated to the calling function. After studying the function definition, can you write the function definition for calculating the area of circle? Pause this video and think about it. First, we declare the function header. Here, return type is a float. Name of the function is area underscore c and it takes the one parameter of type float. Then, we open the curly brace. In curly brace, after that, we define one local variable res to store the result. After that, we calculate the area of circle and we store the result in the res variable. Here, we use the return statement to returning value to the calling function and then we close the function. Next, we will see the function call. A function call is nothing but invoking the function. When the function is called, control of the program gets transferred to the function. Once called function is executed, program control passes back to the calling function. Here, we see the syntax of how to call the function. First, we define the function name and in bracket, we specify the parameter list. Initially, we declare the function name followed by the list of actual parameter or the arguments. Suppose, we want to call the square function. Then, we first define the function name. Here, the function name is square and we pass the actual value to that function. Next, beginning with the sample program. Here, we include the header file. Then, we declare the display function. Then, start with the main function. In main function, we declare one variable of type, well, of type integer i and assign the value 20 to the i variable. Now, we call the display function and pass the value of i to that function. Now, the next step is defining the function body for display function. Here, we declare one local variable k and assign the value 35 to the k. Then, we print the value of j and k and then close the function body. Now, after coding, we compile a program by clicking on the build menu on the menu bar. After compiling, we need to run our program. So, to run, we click on the run from drop down list of the build menu or you can use the shortcut key control f10. Now, you can see the output window. Let us consider another example of function call. Our main focus in this program is to demonstrate when the function returns some value, it is being stored in a variable. So, in this program, first we include the header file. After including the header file, we define define the cube function. Here, the return type of the cube function is integer and it takes only one parameter of type integer. Then, after that, we declare the main function. In main function, we declare the two variables n and res. Then, we take the input from the user by using the scanf function and that value is stored in the n. Then, we call the function. So, here the function call is made by calling the function name with passing the parameters. Then, we display the message cube of the number, cube of the number. After that, we close that main function. Then, we define the actual body of the cube function. In cube function, we first define the one local variable result. After that, we calculate the cube of the number and that value is stored in the result variable. And then, we use the return statement to returning the value to the calling function. Then, after that, we compile the file by click on the build button. Next, we run the file by clicking on the run and it shows the output. These are the references. Thank you.