Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Thursday, February 6, 2020

Function in C

welcome2protec: A function is a group of statements (Block or Piece of code) wrapped with curly braces ({}) that together perform a specific task.

Function in C | welcome2protec.com


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.com
Function in C | welcome2protec


There are two types of function in C
Types of Function | welcome2protec.com
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.

Remember: Since, the definition of predefined functions are stored in library file. Therefore, these functions are also called library function. E.g. scanf(), printf(), strcpy, strlwr, strcmp, strlen, strcat etc. And its declaration stored in header file (.h file). That is the reason to use predefined functions in a program, we need to include appropriate header file (Such as #include <stdio.h> , #include <conio.h> , #include <math.h> etc.) at the beginning of the program. 

For Example: printf() and scanf() functions are declared in <stdio.h> header file. Hence, to use these functions we need to include header file by using #include <stdio.h>  (stands for standard input output).

Same way, to use clrscr() and getch() functions, we need to include <conio.h>  header file by using #include <conio.h> . Since these functions are declared in (stands for console input output) <conio.h> header file.


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

a) Use the same group of statements every time you want to perform the task.
b) Create a function to perform that task, and just call it every time you need to perform that task.

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.













Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

1 Comments:

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us