Functions

Functions are very useful in the modern programming languages. There are many advantages of the functions. It divides the program to the sub-program which is very easy for code and also easy for debugging.

There are two types of functions:

1.      library functions: We have used library functions which are inbuilt in the c compiler and we directly used them.

e.g:      printf();

            getch();

2.      User defined functions: These functions are not inbuilt and we have to write the code for them according to our need. Once we have design a function, we can use it at anywhere in the program by calling it. It will save our time and space.

e.g:

 void star(void)             //definition

{

printf(“********”);

printf(“\n”);

}

void star(void);            // declaration

void main()

{

star();              //calling

printf(“hello”);

star();

}          

Output will be:

********

hello

********

You can see in the above example how function is defined, declare and called. Where we have called the function the control will transfer to the function definition and then executes the code.

There are three parts of a function are as follows:

  1. Function definition
  2. Function declaration
  3.  Function call

 

more:

Category of functions

Posted in C

Leave a Reply

Your email address will not be published. Required fields are marked *