Computer Programming & Problem Solving ( CPPS ) Turbo C Programming For The PC (Revised Edition ) By Robert Lafore

Similar documents
Sir Syed University of Engineering and Technology. Computer Programming & Problem Solving ( CPPS )

Computer Programming & Problem Solving ( CPPS )

Sir Syed University of Engineering and Technology. Computer Programming & Problem Solving ( CPPS ) Pointers. Chapter No 7

A Fast Review of C Essentials Part I

Tutorial No. 2 - Solution (Overview of C)

BLM2031 Structured Programming. Zeyneb KURT

Unit 4 Preprocessor Directives

C: How to Program. Week /Mar/05

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Presented By : Gaurav Juneja

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

Chapter 2 - Introduction to C Programming

Unit 7. Functions. Need of User Defined Functions

Preprocessor Directives

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Technical Questions. Q 1) What are the key features in C programming language?

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

C Language Programming

UNIT 3 FUNCTIONS AND ARRAYS

UIC. C Programming Primer. Bharathidasan University

Chapter 1 & 2 Introduction to C Language

Data Types and Variables in C language

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction

Lecture 2: C Programming Basic

INTRODUCTION 1 AND REVIEW

Fundamentals of Programming Session 4

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

Programming and Data Structure

printf( Please enter another number: ); scanf( %d, &num2);

Preview from Notesale.co.uk Page 6 of 52

Basic Elements of C. Staff Incharge: S.Sasirekha

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

CHAPTER 4 FUNCTIONS. 4.1 Introduction

Creating a C++ Program

LESSON 4. The DATA TYPE char

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

Subject: Fundamental of Computer Programming 2068

Have examined process Creating program Have developed program Written in C Source code

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

UNIT- 3 Introduction to C++

Introduction. C provides two styles of flow control:


Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Programming for Engineers Introduction to C

Introduction to C programming. By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE

CS113: Lecture 4. Topics: Functions. Function Activation Records

Unit 3 Decision making, Looping and Arrays

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Chapter 5 C Functions

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

2. Numbers In, Numbers Out

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #54. Organizing Code in multiple files

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Unit. Programming Fundamentals. School of Science and Technology INTRODUCTION

It is necessary to have a single function main in every C program, along with other functions used/defined by the programmer.

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental of Programming (C)

Intro to Computer Programming (ICP) Rab Nawaz Jadoon

Functions. (transfer of parameters, returned values, recursion, function pointers).

Fundamentals of Programming. Lecture 3: Introduction to C Programming

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

CSc Introduction to Computing

Review. Modules. CS 151 Review #6. Sample Program 6.1a:

Computers Programming Course 7. Iulian Năstac

Programming and Data Structures

MA 511: Computer Programming Lecture 2: Partha Sarathi Mandal

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

Chapter 8: Function. In this chapter, you will learn about

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Course Outline Introduction to C-Programming

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.1

15 FUNCTIONS IN C 15.1 INTRODUCTION

2. Numbers In, Numbers Out

C++ PROGRAMMING BASICS

ANSI C Programming Simple Programs

Computers Programming Course 11. Iulian Năstac

Functions BCA-105. Few Facts About Functions:

QUIZ. What is wrong with this code that uses default arguments?

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

LAB: INTRODUCTION TO FUNCTIONS IN C++

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

Chapter 2, Part I Introduction to C Programming

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park

Multiple Choice Questions ( 1 mark)

Lecture 2 Tao Wang 1

A A B U n i v e r s i t y

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

CS102: Variables and Expressions

C Syntax Out: 15 September, 1995

(Refer Slide Time: 00:23)

Functions in C SHARDA UNIVERSITY. Presented By: Pushpendra K. Rajput Assistant Professor

Government Polytechnic Muzaffarpur.

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Transcription:

Sir Syed University of Engineering and Technology. Computer ming & Problem Solving ( CPPS ) Functions Chapter No 1 Compiled By: Sir Syed University of Engineering & Technology Computer Engineering Department University Road, Karachi-75300, PAKISTAN Muzammil Ahmad Khan Muhammad Kashif Shaikh Course Books Text Book: Turbo C ming For The PC (Revised Edition ) By Robert Lafore Reference Books: 1. Let Us C By Yashavant Kanetkar 2. C By Dissection ( Second Edition ) By Al Kelly & Ira Pohl 2 1

Course Website http://www.ssuet.edu.pk/courses/ce102/ 3 Marks Distribution Assignments + Quiz 10 Mid Term 20 Lab Work 20 Semester Final Paper 50 Total Marks 100 4 2

Functions - Contents Functions Returning a value from a function Sending values to a function Arguments External Variables Preprocessor Directives 5 Functions We have already come across the functions main, printf and scanf. When you write a program of any size you will find that you can use functions to make life a whole lot easier. What we would like to do is write the checking code once and then use it at each point in the program. To do this you need to define a function to do the work for you. Functions are identified by name and can return a single value. We need to tell the compiler the name of our function, what parameters it has, and the type of information it returns. 6 3

What do Functions Do? Avoiding Unnecessary Repetition of Code Probably the original reason functions were invented was to avoid having to write the same code over and over. Organization If the operation of a program could be divided into separate activities, and each activity placed in a separate subroutine, then each subroutine could be written and checked out more or less independently. Separating the code into modular functions also made programs easier to design and understand. 7 What do Functions Do? Independence There is an advantage in making subroutines as independent from the main program and from one another as possible. For instance, subroutines were invented that had their own "private" variables; that is variables that could not be accessed from the main program or the other subroutine.this meant that a programmer did not need to worry about accidentally using the same variable names in different subroutines; the variables in each subroutine were protected from inadvertent tampering by other subroutines. 8 4

Simple Function Using a function is in some way like hiring someone to perform a specific job for you. Sometimes the interaction with such a person is very simple; sometimes it is more complex 9 /* Implementation of simple function */ void name (void) ; void main (void) clrscr( ); name( ) ; getch( ); 10 5

void name (void) int count; for ( count = 1 ; count < = 5 ; count + + ) printf ( SSUET ) ; printf ( \n ) ; 11 Structure of Functions Main ( ) is a function, so it is not surprising that name ( ), which is also a function, looks like it. The only thing special about main ( ) is that it is always executed first. It does not even matter if main ( ) is the first function in the listing, you can place other functions before it and main ( ) will still be executed first. In this example, main ( ) calls the function name ( ). Calls means to cause to be executed To prints the statement 10 times, main calls name ( ) twice. 12 6

Structure of Functions There are three program elements involved in using a function: 1. Function definition, 2. Call to the function, and 3. Function prototype 13 Function Definition The function itself is referred to as the function definition. The definition starts with a line that includes the function name, among other elements: i.e void name ( void ) This line is the declarator. The first void, means that name ( ) does not return anything, and the second means that it takes no arguments. 14 7

Function Definition Note that the declarator does not end with a semicolon. It is not a program statement, whose execution causes something to happen. Rather, it tells the compiler that a function is being defined. The function definition continues with the body of the functions enclosed in the braces. 15 Calling the Function As with the C library C functions we have seen such as printf ( ) and getch ( ), our user-written function name ( ) is called from the main ( ) simply by using its function name, including the parentheses following the name. The parentheses lets the compiler know that you are referring to a function and not to a variable or some thing else. Calling a function like this is a C language statement, so it ends with a semicolon. name ( ) ; 16 8

Sir Syed University of Engineering and Technology. Calling the Function This function call causes control to be transferred to the code in the definition of the name ( ). This function execute the written statements in the function, and then returns to the main ( ), to the statement immediately following the function call. 17 Function Prototype ( Declaration ) This is the third function related to the function example. This is the line before the beginning of the main ( ). void name ( void ) ; This looks very much like the declarator line at the start of the function definition, except that it ends with a semicolon. What is its purpose? 18 9

Function Prototype ( Declaration ) All the variables are defined by name and data type before they are used. A function is declared in a similar way at the beginning of a program before it is called. The function declaration or (prototype) tells the compiler the name of the function, the data type of the function returns (if any), and the number and the number and data types of the function s arguments (if any). 19 Function Prototype ( Declaration ) In the above example, the function returns nothing and takes no arguments; hence the two voids. The prototype is written before the main ( ) function, This causes the prototype to be visible to all the functions in a file. 20 10

Function Prototype ( Declaration ) The key thing to remember about the prototype is that the data type of the return value must agree with that of the declarator in the function definition, and the number of arguments and their data types must agree with those in the function definition. In the above example, both the return value and the arguments are void. 21 Summary A prototype declares a function. A function call executes a function. A function definition is the function itself. 22 11

Local Variables The variable count used in the function is known only to name ( ) ; it is invisible to the main ( ) function. If we added this statement to main ( ) (without declaring a variable count there ): printf ( %d, count ) ;we would get a compiler error because main ( ) would not know anything about this variable. We could declare another variable, also called count, in the main ( ) function; it would be a completely separate variable, known to main ( ) but not to name ( ). 23 Local Variables A local variable will be visible to the function it is defined in, but not to others. A local variable used in this way in a function is known in C as an automatic variable, because it is automatically created when a function is called and destroyed when the function returns. The length of time of a variable lasts is called its lifetime. 24 12

A Sound Example This program uses the special character \x7, which is called BELL in the standard ASCII code. On the PC, printing this character, instead of ringing a bell, causes a beeping sound. 25 void beep (void) ; void main (void) beep ( ) ; void beep (void) long count ; printf ( \ x 7 ) ; delay ( 10000 ) ; printf ( \ x 7 ) ; 26 13

Delay Function The delay function suspends execution for interval (milliseconds). With a call to delay, the current program is suspended from execution for the time specified by the argument milliseconds. Declaration: void delay ( unsigned milliseconds ) ; 27 Function that returns a value A function that uses no arguments but returns a value performs a similar role. You call the function; it gets a certain piece of information and returns it to you. The function getche ( ) operates in just this way; you call it without giving it any information and it returns the value of the first character typed on the keyboard. Suppose we wanted a function that returned a character as getche ( ) does, but that also automatically translated any uppercase characters into lowercase 28 14

/* Implementation of lower case character using function */ char getlc (void) ; void main (void) char chlc; printf ( Type a for the selection, b for the second: ) ; chlc = getlc ( ) ; 29 switch ( chlc ) case a : printf ( \n You typed an a. ) ; break; case b : printf ( \n You typed a b. ) ; break; default : printf ( \n Non-existent selection. ) ; getch ( ); 30 15

char getlc (void) char ch; ch = getche ( ) ; if ( ch > 64 && ch < 91 ) ch = ch + 32 ; return ( ch ) ; 31 Output: Type a for the selection, b for the second: a You typed an a. Type a for the selection, b for the second: A You typed an a. Type a for the selection, b for the second: c You chose a non-existent selection. 32 16

Note Our new function, getlc ( ), returns a value of type char. The return type is no longer void as in the previous examples. Notice that both the prototype and the declarator in the function definition begins with char to reflect this fact. Just as in the case of getche ( ), the function itself appears to take on the value it is returning. It can thus be used as if it were a variable in an assignment statement, and the value returned ( a lower case character ) will be assigned to the variable, chlc which is then used in the switch statement to determine which message will be printed. Notice how the capital A typed by the user is successfully converted to the lowercase. 33 Return Statement The return ( ) statement has 2 purposes. First, executing it immediately transfer control from the function back to the calling program, and Second whatever is inside the parentheses following return is returned as a value to the calling program. The return ( ) statement need not to be at the end of the function. It can occur anywhere in the function; as soon as it is encountered, control will return to the calling program. 34 17

Return Statement Example char getlc (void) char ch; ch = getche ( ) ; if ( ch > 64 && ch < 91 ) return ( ch + 32 ) ; else return ( ch ) ; 35 Returning Type int The return statement can also be used without the parenthesis. When this is the case, no value is returned to the calling program. Return statement can also return a value of type int i.e integer. Here is the example in which function getmins ( ), gets a time in hours and minutes from the user. The main program uses this function to calculate the difference in seconds between two times. 36 18

int getmins (void) ; void main (void) int mins1, min2 ; printf ( Type first time ( from 10 : 15 ) : ) ; mins1 = getmins ( ) ; printf ( Type second time ( later 11 : 30 ) : ) ; mins1 = getmins ( ) ; printf ( Difference is %d minutes., mins2 mins1 ) ; getch ( ); 37 int getmins (void) int hours, minutes ; scanf ( %d : %d, &hours, &minutes ) ; return ( hours * 60 + minutes ) ; 38 19

Output: Type first time ( from 10 : 15 ) : 6 : 00 Type second time ( later 11 : 30 ) : 7 : 45 Difference is 105 minutes. 39 Returning Type Float Here is the example in which a function returns type float. In this program, the main ( ) function asks the user for the radius of a sphere, and then calls a function named area ( ) to calculate the area of the sphere. The area ( ) function returns the area of the sphere in the form of a floating point value. 40 20

float area (float) ; void main (void) float radius ; printf ( Enter radius of a sphere : ) ; scanf ( %f, &radius ) ; printf ( Area of a sphere is %.2f, area (radius) ) ; getch ( ); 41 float area (float rad) return ( 4 * 3.14 * rad * rad ) ; Output: Enter radius of a sphere : 10 Area of a sphere is 1256.64 42 21

Limitation of return ( ) statement mer should be aware of a key limitation in the use of the return ( ) statement: you can only use it to return one value by a function. 43 Using Argument to pass data to a Function The mechanism used to convey information to a function is the argument. You have already used arguments in printf ( ) and scanf ( ) functions; the format strings and the values used inside the parentheses in these function are arguments. 44 22

/* Draws Bar-graph and Implementation of Function Arguments */ void bar ( int ) ; void main (void) printf ( Ali \t ) ; bar (10) ; printf ( Babar \t ); bar (15) ; printf ( Faraz \t ) ; bar (20) ; getch ( ); 45 void bar (int score) int count ; for ( count =1 ; count < = score ; count ++ ) printf ( \xcd ) ; printf ( \n ) ; 46 23

Output: Ali ========== Babar =============== Faraz ==================== This program generates a bar graph of names and bars representing, say the score in a spelling test. In this program the purpose of the function bar ( ) is to draw a horizontal line, made of the double line graphics character ( \xcd ) on the screen. 47 Structure of a Function Call with Arguments bar (27) ; In the function definition, a variable name score is placed in the parentheses following bar : void bar ( int score ) This ensures that the value included between parentheses in the main program is assigned to the variable between parentheses in the function definition. Notice that the data type of the score is also specified, in the function definition. This constitutes a definition of the argument variable, setting aside memory space for it in the function. 48 24

Passing Variables as Arguments In the above example we passed constants (such as the number 27) as an argument to the function bar ( ). We can also use a variable in the calling program as this variation on the program discusses above of the bar graph. 49 void bar ( int inscore ) ; void main (void) int inscore = 1 ; while ( inscore! = 0 ) printf ( Score = ) ; scanf ( %d, &inscore ) ; bar ( inscore ) ; /* Actual Arguments */ 50 25

void bar (int score) /* Formal Arguments */ int count ; for ( count =1 ; count < = score ; count ++ ) printf ( \xcd ) ; printf ( \n ) ; 51 Output Score = 20 ==================== Score = 10 ========== Score = 25 ============================ 52 26

Note Different names have been assigned to the arguments in the calling and called functions; inscore in the calling program and score in the function. Actually, we could have used the same name for both variables; since they are in different functions, the compiler would still consider them to be separate variables. 53 Note The argument in the calling program is referred to as the Actual Argument, while the argument in the called function is the Formal Argument. In this case, the variable inscore in the calling program is the actual argument, and the variable score in the function is the formal argument. 54 27

Sir Syed University of Engineering and Technology. Using More than One Function You can use as many functions as you like in a program, and any of the functions can call any of the other functions. In C Language, all functions including main ( ) have equal status and are visible to all other functions. 55 /* Implementation of Multi Functions */ int sqr ( int ) ; int sum ( int, int ) ; int sumsqr ( int, int ) ; void main (void) int num1, num2 ; printf ( Type 2 numbers: ) ; scanf ( %d %d, &num1, &num2 ) ; printf ( Sum of the squares is %d, sumsqr ( num1,num2) ) ; 56 28

void sumsqr ( int j, int k ) return ( sum ( sqr ( j ), sqr ( k ) ) ) ; void sqr ( int z ) return ( z * z ) ; 57 void sum ( int x, int y ) return ( x + y ) ; 58 29

External Variables While local variables are preferred for most purposes, it is sometimes desirable to use a variable known to all the functions in a program rather than just one. This is true when many different functions must read or modify a variable, making it clumsy or impractical to communicate the value of the variable from function to function using arguments and return values. In this case, we use an External Variables (sometimes called a global variable). 59 /* Implementation of External Variables */ void oddeven ( void ) ; /* Function Prototype */ void negative ( void ) ; int keynum; /* External Variables */ void main (void) printf ( Type Keynum: ) ; scanf ( %d, &keynum ) ; oddeven ( ); /* Function Call */ negative ( ); 60 30

void oddeven ( void ) if ( keynum % 2 ) printf ( Keynum is Odd. \n ) ; else printf ( Keynum is Even. \n ) ; 61 void negative ( void ) if ( keynum < 0 ) printf ( Keynum is Negative. \n ) ; else printf ( Keynum is Positive. \n ) ; 62 31

Output: Type Keynum: - 25 Keynum is Odd. Keynum is Negative. Type Keynum: 50 Keynum is Even. Keynum is Positive. 63 Note There are several reasons why external variables are not good idea. First, external variables are not protected from accidental alteration by functions that have no business modifying them. Second, external variable use memory less efficiently than the local variables. The rule is that variables should be local unless there is a very good reason to make them external. 64 32

Preprocessor Directives Preprocessor directives on the other hand, are instructions to the compiler itself. Rather than being translated into machine language, they are operated on directly by the compiler before the computation process even begins; hence it named preprocessor. 65 Preprocessor Directives Normal program statements are instructions to the microprocessor; Preprocessor directives are instructions to the compiler. Preprocessor directives always start with a number sign ( # ). The directives can be placed anywhere in a program, but are often used at the beginning of a file, before main ( ), or before the beginning of particular functions. 66 33

Sir Syed University of Engineering and Technology. The # define Directive /* Implementation of define directive */ # define P I 3.14159 float area ( float ) ; /* Function Prototype */ void main (void) float radius ; printf ( Enter radius of the sphere: ) ; scanf ( %f, &radius ) ; printf ( Area of the sphere is %.2f, area (radius) ); 67 The # define Directive float area ( float rad ) return ( 4 * P I * rad * rad ) ; 68 34

The # define Directive The preprocessor first looks for all program lines beginning with the number sign ( # ). When it sees the # define directive, it goes through the entire program, and at every place it finds PI it substitutes the phrase 3.14159. It is very much like a word processor s global search and replace. 69 The # define Directive The phrase on the left ( P I ), which will be searched for it, is called the identifier. The phrase on the right ( 3.14159 ), which will be substituted for it, is called the text. A space separates the identifier from the text. By convention, the identifier is written in all caps. This makes it easy when looking at the listing to tell which part of the program will be altered by # define directives. 70 35

Why use # define? With the help of the # define directive, we have made our program easier to read. Ordinarily, you would need to go through the program and manually change each occurrence of the constant. However, if you have defined 3.14159 to be PI in a # define directive, you only need to make one changer, in the # define directive itself: 71 Why not use variable names? A variable could also provide a meaningful name for a constant, and permit one change to effect many occurrence of the constant. It is true, a variable can be used in this way. 72 36

Why not use variable names? However, there are at least three reasons why it is bad idea. First, it is inefficient, since the compiler can generate faster and more compact code for constants than it can for the variables. Second, using a more compact code for constants encourages sloppy thinking and makes program more difficult to understand it. Third, there is always the danger that a variable will be altered inadvertently during the execution o the program so that it is no longer the constant you think it is. 73 The const Modifier The new ANSI standard C defines a modifier, const that can be used to achieve almost the same effect as # define when creating constants. For example const float PI = 3.141592 ; This const tells the compiler not to permit any changes to the variable, so if you try to modify PI you will get an error message from the compiler. 74 37

Macros The additional power comes from # define is the ability to use arguments. A # define directive can take arguments, much as a function does. A Macro generates more code but executes more quickly than a functions. 75 Macros # define WRITE printf ( SSUET ); void main (void) printf ( CPPS-1 ) ; WRITE getch ( ); 76 38

Macros # define PR ( n ) printf ( %.2f \n, n ) ; /* macro definition */ void main (void) float num1 = 12.34 ; float num2 ; num2 = 5.0 / 2.5 ; PR ( num1 ) ; PR ( num2 ) ; CPPS - Chapter No1 : Functions 77 Macros # define SUM ( x, y ) x + y /* macro definition */ answer = 10 * SUM( 1, 2 ) 78 39

The # include Directive The # include directive causes one source file to be included in another. instead of having to rewrite all the macro every time you wrote a program that used them, you could insert them into the.cpp source file using the # include directive 79 /* Implementation of the # include directive */ # include<stdio.h> # include<conio.h> # include " c:\ tc\bin\ my.h " void main ( void ) int a, b, ans = 0 ; printf ( " Enter any two numbers: \n " ) ; scanf ( " %d %d ", &a, &b ) ; mul ( a, b ) ; 80 40

/* Implementation header file my.h */ void mul ( int, int ) ; void mul ( int aa, int bb ) int ans ; ans = aa * bb ; printf ( " Answer = %d ", ans ) ; 81 The # include Directive There are actually 2 ways to write # include statements. The variation in format tells the preprocessor where to look for the file you want included. The variation shown above # include my.h shows the file name surrounded by quotes. This causes the preprocessor to start searching for the file in the directory containing the current source file. The other approach is to use angle brackets # include <stdio.h>. This format causes the preprocessor to start searching in the standard header directory. 82 41

Standard Header Files Another reason to use the header files is to provide prototype of library functions. Each library function provided with Turbo C is associated with a header file: that is, a file with the extension.h that is kept in the \ INCLUDE directory. The prototype for the function is part of the corresponding header file. 83 Class Assignment No 5. 1. Differentiate between function definition and function declaration. 2. Write a program to calculate the factorial of a input number using a user defined function. 3. What is the purpose of Macro in C language. 4. Write a program that implements a macro. 5. Write a program that implements a user defined header file. 84 42