Why function in c programming?

A function is a block of statements that performs a specific task. Imagine, you are making a c program. And you need to display some data frequently. One solution is to write the entire code to display the score again and again. But there is another better solution using functions, we can define that entire code in a function once and call it whenever you want.

  • Program development made simple : Work can be divided among project members thus implementation can be completed in parallel.
  • Program testing becomes simple : Easy to locate and isolate a faulty function for further investigation
  • Code re-usability increases : Reusability is the main achievement of C functions.
  • Functions facilitate the factoring of code : Every C program consists of one main( ) function typically invoking other functions, each having a well-defined functionality.

Syntax of function declaration

return_type function_name( parameters ){
    function body;
};
  • Return type : Return type defines the data type of value returned by the function.
  • Function Name : This is the actual name of the function. The function call and the parameter list collectively represent the function signature.
  • Parameter'(s) - A feature might also be given enter. Parameter listing consists of input kind and variable name given to the feature. multiple inputs are separated the use of comma ,.

Types of functions

C programming language provides the following types of functions.

  • Library Functions
  • User-defined Functions

1. Library Functions

C Library functions are inbuilt functions in C programming. To use Inbuilt Function in C, you must include their respective header files, which contain prototypes and data definitions of the function.

The syntax of the for loop is as follows:

Built in Library header files

OperatorsDescriptionExample
Add two operandsM+N = 15
-(Subtraction)Subtract two operandsM-N = 5
*(Multiplication)Multiply both operandsM*N = 50
/(Division)Divide numerator by denominatorM/N = 2
%(Modulus)Modulus Operator and remainder of after an integer divisionM%N = 0
++(Increment)Increment operator: increases integer value by oneN++ = 6
--(Decrement)Decrement operator: decreases integer value by oneN-- = 4
#include   

where filename represents the name of the header file.

For example: If you want to use printf() function, the header file should be included.

#include
#include
void main(){
 // If you use printf() function without including the 
    // header file, this program will show an error. 
  printf("Learn c language"); 
 getch();
}

Output

Learn c language
Continue...........