 Hello, everyone. Myself, Mr. F.R. Syed. I work as an assistant professor in the Department of Computer Science and Engineering at Walsh and Institute of Technology, Singapore. The topic for my today's lecture is file inclusion in C language. Meaning, how do you include files in a C program? That concept we are going to see in this lecture. The learning outcome and at the end of this session, the students will be able to describe the file inclusion pre-processor directive in C language. Let us first see what is a pre-processor in C language. A pre-processor is actually a program that processes the source program before it is passed to the compiler. The pre-processor commands are the directives that actually form what can almost be considered like a language within C language. We can certainly write some C programs without knowing anything about the pre-processor or the facilities that it provides. And the pre-processor is actually a great convenience that virtually all programmers of C language rely on it. Now, let us see this diagram. In this diagram you can see what are the different phases right from the point where a program has been returned up to the point when the program is executed. So, as you can see initially there is handwritten program. Of course, that is being written on a text editor which actually can be called as a C source code. Let us say for example, the name of the program is pr1.c. Then comes into picture this pre-processor and this code source code when it is passed to this pre-processor actually generates the expanded source code. We can say the name pr1.i. Then we have the compiler coming into picture which actually converts that code, expanded source code into the object code. Of course, the file being named as pr1.obj. And finally, the linker comes into picture and with the help of the linker we get the executable code pr1.exe. So, now we have different processors to which let us see what are the input and what output does it give. So, for an editor what we can say what was the input? The input was a program typed from the keyboard by the user and what output does it generate? It generates a C source code that contains the program and the preprocessor commands. Then we have the preprocessor that takes as input the C source code file and converts it into the source code file with the preprocessing commands that are properly sorted out. Then we have the compiler which takes a source code file with preprocessing commands which are sorted out and it generates a relocatable object code. And finally, the linker it converts the relocatable object code and the standard C library functions into the executable code in the machine language. Let us see these preprocessor directives. The preprocessor offers some features which are called as preprocessor directives. Each of these directives generally begins with a hash symbol. So, the directives can be actually placed anywhere in a program. Those are mostly placed at the beginning of the program. Exactly the point where we can see the first function definition we have just before that. Here the four preprocessor directives that we have listed out. The first one is the file inclusion. Of course, where we will make use of a file which will be included in a program generally with the help of hash include preprocessor directive. The second one will be the related to macro expansion some macros we make use of. Then we have some conditional compilation preprocessor directives and finally, some miscellaneous directives. So, today in this lecture we will see the first one the file inclusion. Now what is file inclusion? Now this file inclusion will help us to include one file into another one. That means, I have written my C program and if suppose I want some of the features of some other program some functions that have been declared in other program. I want those to be included in my program without writing the code for those functions. So, that I can do using file inclusion. Let us move ahead. The preprocessor command generally looks like this as shown below hash include and then we write the name of the file which we are going to include or whose features we are going to include in our program. So, this file inclusion generally causes the entire contents of the file which is of course, named with the file name word to be inserted into the source code. And of course, this file inclusion generally presumes that the file that is being included is already existing. So, only those files we can include. So, we have as an example for file inclusion as you can see the program where first of all we have included the header file stdio.h, then we have included something new that we are seeing for the first time hash include in double quotes sample.h. So, the sample.h will be actually the file that I am trying to include in my program or whose features features meaning the functions and macros I am interested to use in my program. So, before using those I can include that file and then I can directly use that without writing a code for that separately. So, then in the main function what I do is I declare two variables b and c, c value initialized to 5 and then I am calling a function as fun into bracket the parameter I have passed as c and the value that this function will be returning I will be storing in b. So, there could be chances that if suppose I do not include this line of sample.h that is I do not include the header file sample.h then probably this line will raise an error meaning that this fun function is undefined is not existing. Now because the sample.h header file I have included in my program. So, probably what I can say is this fun function may be having its definition in this header file where it is taking one parameter and returning one integer value. So, with the help of that this program could compile properly without any errors and then it could run. So, what output can we expect over here is anything that this fun function could perform as an operation whatever answer it returns that will be stored in b and then that output we are going to see over here with the help of print of statement. So, for this program there is no output given because I have not specified the sample.h header file contents. So, therefore you can understand that with the help of this I just tried to show how to make use of a function which is not defined in a program, but which is defined in some other program and how to use how to include that file in this program. So, that is what was a simple example of file inclusion. Now the students are expected to think and write the answer to the following question. So, now students are expected to find the output to this program. So, pause the video and write your answer. Now the output of the program is 7. Now how did that output as 7 come? Now as you can see here when we call the function val by passing the variable s value that is 5. So, that 5 was stored in m. So, when we see in this function val the operation that performed is this one an arithmetic operation where you can see 9 minus 2 multiplied by m. Now m value passes 5. So, 2 into 5 that is 10. So, as we can see there will be the precedence of operators rule being applied the operators star and slash will be given first priority. So, therefore, 2 into 5 10 will be evaluated first then 40 divided by 5 8 will be evaluated after we have these two values evaluated then we will perform 9 minus 10 equal to minus 1 plus 8 equal to 7. So, therefore, you get the output as 7. Now the important thing to be understood over here is the way how this header file has been included and how that function has been called it is the similar way as we generally use or we generally call built-in functions by just including a header file at the top. So, similar to that we have included a header file sample.h. So, now let us discuss on the point as to when and why to use this file inclusion what are the advantage of using this file inclusion or maybe the area or the application where I can make use of this file inclusion how can it benefit me. So, one of the application that is listed over here is if suppose you have a large program and you need to manage the entire code in a proper way. So, in that case what you can plan is you can plan for dividing the code into different files. Now how can this division be done? So, you can make use of the fact that it will be best to keep the different sections of the program separate and the separate things that we are going to keep we are going to keep in such a way that all the relevant functions or all the functions that are actually doing a particular relevant task that is some or somewhere directly or indirectly related those things can be kept in one file. So, such kind of files are then included using the hash include preprocessor directive at the beginning of the program. So, as we have done already. So, another application could be when some functions and macros are almost needed in every program or majority of the programs make use of some functions and macros and we now see that all the time defining such functions and macros will be actually time consuming as well as will place a burden on the program or of writing the same kind of code again and again. So, in that case such functions and macros can be written in a separate file and whenever required that file can be included in your program, inclusion of that file in your program will just add all the statements of that file to your program. So, that is how this file inclusion will benefit you. So, now this generally we make use of the dot h extension to mean that it is a header file and generally the such kind of file inclusion is done at the head of the program at the top of the program code not compulsory, but generally we declare the header files inclusion at the top of the program and the prototypes of the different library functions that we have these are actually grouped into different categories and accordingly then stored in some specific header files in which you will find out like for example, all the mathematics related functions are kept in the header file mac dot h and all the standard library functions for input output are kept in the stdio dot h header file. So, how can we include a file in our program is we have total two ways for including a file in your program the first one is this way hash include then in the angular brackets you will write down the file name of course, it could be an example of stdio dot h hash include stdio dot h or we may also have in some cases hash include stdlib dot h generally these are the header files that are built in. The second way is hash include and in double code you will write down the name of the header file that the user has defined like example, hash include sample dot h which we have already used in the previous program. So, now what could be the advantages of using file inclusion the first one is if there are suppose macros and functions which are used repeatedly in your program then it is better to write such functions and macros separately in a program and make a header file. So, whenever a programmer requires he will just include the header file in his program and accordingly call those functions to perform his task. Also if suppose there are big projects there the separate related files can be handed over to separate teams and the task related to those files can be assigned to separate team members and accordingly the work can go in parallel. So, that is one more advantage of that the third advantage is it is easy to find bugs then debug and accordingly unit test the project. So, file inclusion does help the programmer with this and finally, the source code will look less clumsy and more readable if suppose file inclusion is made use of. So, these are the references for the video lecture. Thank you.