A function is a group of statements (Block or Piece of code) wrapped with curly braces ({}) that together perform a specific task is called function. It has a name for its identification. When the functions are called, they execute and perform their respective tasks.
Let's understand with a simple example:
Function in C | welcome2protec |
- Pre Defined Function
- Pre Defined Function
- User Defined Function
- Why do we use a function?
- Advantage of using function
- More about function
Quick links:
There are two types of function in C
Types of function | welcome2protec.com |
Predefined Function:
The C standard library provides numerous built-in functions. Such as printf(), scanf(), clrscr(), getch(), strcpy(), strcmp() etc. This functions are already defined (defined means created) by the professionals known as predefined function. We can directly call these function in the program whenever we need it.
User Defined Function:
Any function defined (defined means created) by the user in a program is called user defined function. Its because, C allows you to define function according to your need.
In the next tutorial, we will learn how to create user defined functions and how to use them in C Programming.
Why do we use function in C language?
Function are used for divide a large code into module (smaller one), due to this we can easily debug, maintain and reduce the complexity of big task (Program).
For Example: Suppose you are building an application in C language and in one of your program, you need to perform a same task more than once. In such case you have two options
Using option (b) is a good practice and a good programmer always uses functions while writing codes in C.
Advantage:
- Modularization.
- Easy to Modify.
- Easy to Debug.
- Better Memory Utilization.
- Avoid repetition of codes.
- Increases program readability.
- Reduces chances of error.
- Properties of function
- User defined function
- Types of user defined function
- Function call by value
- Function call by reference
- Library function
Hi 👋
ReplyDelete