Functions of C Language, Importance And Its Types
What is a function and its importance?
A function is a piece of code that is designed to perform a specific task. It is a complete and independent program. It is executed by the main function or any other function of the program.
Following is the importance and advantages of functions:
1. A large computer program may consist of several hundred statements. If this program is written as one long program, it becomes difficult to understand, test and debug. To make the program simple, it is divided into smaller and independent units or modules. These modules are written as functions.
2. Each function is written to perform a specific task. It is written as an independent program. I is written and tested independently. This makes writing and testing of program easier.
3. since each function is an independent program, is is written independently. Thus several programmers can work on one program simultaneously and develop a program quickly.
4. Once a function has been written and tested, it can also be used in other program. For example, if a function is written to compute average of values, it can be used in any program that needs to compute average of values.
5. Use a function also reduces overall length of the program. A program may include steps that are repeated. These steps are written as a function. Whenever these steps are to be repeated, the function is executed.
How many types of functions are used in C and difference between them??
There are two types of functions in C language. These are built-in functions and user-defined functions.
Built-in Functions:
The functions that have already been defined as a part of the language and can be used in any program are called built-in functions. These are also called library functions. These functions are defined in header files. To use a built-in function in a program, the header file containing the function must be included in the program using a preprocessor directive.
For example, to compute the square root of a number, sqrt function is used. This function is defined in the math.h header file. If this function is used in the program, then the math.h header file must be included using the preprocessor #include directive.
User-Defined Functions:
The functions created by a user is called user-defined functions. These are also called programmer-defined functions. These are written to perform one specific task in the program. These functions are written for a specific use.