C Programming Questions and Answers

Questions Index

Question: What is function in C? What are the advantages of using function?

Answer:

A function in C is a block of statements that has a name and can be executed by calling it from some other place in your program. Functions are used to divide complicated programs into manageable pieces.

C functions can be classified into two categories:
1. Library functions
2. User-defined functions

Library functions are those functions which are already defined in C library, example printf(), scanf() etc. To use library functions, you need to include appropriate header file.

A user-defined functions are those functions which are defined by the user at the time of writing program.

Using functions has several advantages:
Different people can work on different functions simultaneously.
If a function is needed in more than once, you can write it once and use it many times.
Using functions greatly enhances the program’s readability because it reduces the complexity of the function main.