Professional Documents
Culture Documents
Paramita Mitra
Outline
What is function. Types of function.
Necessity of function.
Advantages of function. Key points of multi function program.
What is a Function ?
Function is a self contained block of statements that perform a coherent task of some kind. Every C program can be thought of to be a collection of functions.
Types of Functions
Library functionsThese are the in built functions in c library. These are already defined in header files. e.g. printf( ); is a function which is used to print an output. It is defined in stdio.h file . User defined functionsProgrammer can create their own function in C to perform specific task.
Advantages
Top down modular programming. Length of the source code can be reduced.(reduction of code size) Easy for debugging Function sharing
o/p-
I m in message I m in main
Summarization
main( ) itself is a function from which we are calling the function message( ) A function gets called when its name is followed by an opening and a closing parenthesis and then with a semicolon. The activity of main( ) is temporarily suspended and message( ) function goes to work. When the message( ) function runs out of any statement to execute, the control returns to main( ),where it let off.
Summarization Contd
C Program is a collection of one or more functions. Any C Program must contain at least one function. If program contains only one function it must be main( ). There is no limit on the number of functions present in a C program. After each function has done its job, control returns to calling function, where it let off.
Summarization Contd
A function can be called from another function but can not be defined in another function. It should be defined outside of the main.
Conclusion Writing function avoids rewriting the same code again and again. Using functions it becomes easier to write programs and keep track of what are they doing. Cram the entire logic in one function is not suggestive. Break a program into small units and write functions. These functions perform some logically isolated task.
THANK YOU