A function is a self contained block or sub program of one or more statements that performs a specific task when called. C functions can be classified into two categories: Library functions and user defined functions.
1. Library functions are those functions which are already defined in " C Library".
Ex: printf();
you just need to include appropriate header files to use these functions. These functions are already declared and defined in " C libraries" .
2. User defined functions are those functions which are defined by the user at the time of writing program to made for code reusability and for saving time and space.
Benefits of Using Functions
- It provides modularity to your program's structure.
- It makes your code reusable. You just have to call the function by its name to use it, wherever required.
- In case of large programs with thousands of code lines, debugging and editing becomes easier if you use functions.
- It makes the program more readable and easy to understand.
In a C program we use both user defined and predefined functions. But, in order to use user defined functions you need to tell what is it ( function declaration), when to use it (function call), how to use it (function definition).
Here is simple example program using functions which prints a simple greeting message.
void display(); // function decleration void main() { display(); /* function call */ } void display() / * function definition */ { printf(" welcome to programming using functions"); }
0 comments :
Post a Comment
Note: only a member of this blog may post a comment.