Sunday, 8 January 2012

Episode 13 : Function


Function

Function is a procedure that divided the program into different part for execute one or more statement or instruction.
Function is for make program to easy and finish step by step process. It also increase the reusability of code and we can use these function in different location in our program.
Dividing the program into different small part is called modular programming.

For small program we can declare instruction into main() function but when we write long program like as  we write a database program for an company then we need to define many instruction for different operation like insert data, delete data, modify data etc. If we write these instruction into only  main() function then so much difficult to understand. If we define function by categories it will be so easy and better understand.

There are two types of Function

1.     Library Function : In our previous example , we use printf() function for showing something to the screen. How to work this function it is defined by the compiler and we are just use this function but we are not written this function. Many function are declared previously like printf(), scanf() main() etc. is called library function.

2.     User-defined Function : For our needed, we use so many library function but we need to create another function for our program which is made by us. These function is called user-define function

Example :



Output :


Here declare a user-define function name msg() outside the main() function and we called that function from the main() function. Compiler  start compile from the main(), when compiler find that any function called then the compiler stop compile the main() and find the calling function and execute that function and after execution the calling function compiler come back to the main() function and execute the other statement.

[* When compiler find the second bracket then the compiler define it to function. ]

I hope you are understand the matter.

Written by “Shojib”

No comments:

Post a Comment