C – Functions

After reading this C functions topic, you will able to use it in C programming, you will understand the user-defined function structure also you will know the user-defined function advantages.

In real life, instead of doing all task alone, we generally get our work through others i.e. we divide our work. That’s why C language provides us with a subprogram facility called function.

Types of Functions

Functions can be classified into two categories

  • Library functions or standard functions.
  • User-defined function.

Library functions are the predefined function in a compiler and some of their examples are printf() and scanf(), also both defined in stdio.h header file. In C Programming, user place header files at the beginning of the program to use a corresponding library function. In general, all similar types of library functions are grouped under one header file means to say library functions like pow(), sin(), etc all are used for performing the mathematical operation defined in only math.h header file. The user-defined function is written by the user at the time of program writing. All the library and user-defined functions can be called from function main().

Advantages of Function

  • A function is easier to understand, debug and test.
  • The length of the source program can be reduced using a function at a specific position.
  • A user-defined function can place into existing library function or a user can define all similar types of the user-defined function under a user define header file.

User-defined function Structure

When we write user defined function structure generally having three parts i.e. function declaration, function call, and function definition represent below.

Function Declaration

The function declaration also referred as function prototype and function declaration part help the compiler to check data type and the number of arguments that we will pass later on are correct or not.

Function Call

The function call really calls the function. When a function call, it may or may not pass any argument. When it passes arguments, it must be in accordance with the function declaration.

Function Definition

The function definition having the statement(s) which executes when function called and after that function returns back to calling function. Here function may or may not return value.

Published by

Electrical Workbook

We provide tutoring in Electrical Engineering.

Leave a Reply

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