Types of Function in C
A function is a piece of code that accomplish a certain operation for a specific task.
There are two types of functions in C:
- System-defined function (Library Function)
- User-defined function
1. System defined Function (Library Function):
The system-defined functions are also known as the pre-defined standard library functions, which are already defined in the C library.
Functions such as printf() , scanf() ,put() ,gets(), etc., are the library functions.
These functions are already specified in header files, and such header files start with a .h extension, for example <stdio.h>. We call these header files when we need to use them.
When we use the pre-defined functions, we must include the header file as the header file contains the declaration of a pre-defined function.
2. User-defined function:
The C programming language allows programmers to define their functions despite having hundreds of library functions. User-defined functions are those that are defined by the end-user of the software. According to the requirements, a programmer may define any number of functions.
The declaration and function definition of a user-defined function is a must. Without the declaration and definition, we cannot access our user-defined function.
The definition of the function is executed each time it is called.
For example, Let’s say we create a function called sum() with two parameters and a return value, then its declaration and definition can be done as illustrated in below code:
Program:
#include<stdio.h>
int main(){
int number1, number2, output ;
int sum(int,int) ; // function declaration
printf("Enter any two integer numbers : ") ;
scanf("%d\n%d", &number1, &number2);
output = sum(number1, number2) ; // function call
printf("Sum of the two number is = %d", output);
return 0;
}
int sum(int x, int y) // function definition
{
return x+y ;
}
Explanation:
- Here we have declared a function "int sum(int, int)," which has two arguments and the return type is int.
- Function definition runs the code contained therein, returning to the function call with the return value.
- The calling function "sum(number1, number2)" gets the execution control back from the return, which is present in the sum function body. And the value of "x+y" replaces the calling function, and this value is assigned to the output.
- We get our sum of two numbers on display due to the printf() function.
Program Output:

The function call works as below:
- When we call a function, the execution control moves from the calling function to the called function.
- When the execution of the called function is completed, the execution control moves back to the calling function from the called function.
- The called function arguments receive one or more data from the calling function. In contrast, after completing the execution of the called function, the called function gets control back and receives only one value known as the "return value". This means that the data values transmitted from the calling function to the called function are referred to as parameters. The data values transferred from the called function to the calling function are known as returned values.
Categorization of Functions based on Arguments and Return Value
The functions are categorized as follows based on the data flow between the calling function and the called function.
- Without arguments and without return value
- With arguments and without return value
- Without arguments and with return value
- With arguments and with return value
1. Without arguments and without return value:
These types of functions have no arguments in parentheses and do not return any value.
This means in these types of functions, we would not pass any parameter while defining, declaring, or calling it.
Between the caller function and the called function, no data is sent.
Syntax:
void FunctionName()
{
// function body contains statement
}
Program:
#include<stdio.h>
int main(){
int sum() ; // function declaration
sum() ; // function call
return 0;
}
void sum() // function definition
{
int number1, number2 ;
printf("Enter any two integer numbers : ") ;
scanf("%d\n%d", &number1, &number2);
printf("Sum of the number1 and number2 is= %d", number1+number2 ) ;
}
Explanation:
- Here we declared a function "int sum()" which has no arguments and does not return any value.
- When the execution starts, then the control goes on calling the function. As we call our sum() function, control goes to the sum() function body.
- Because this sum() function takes nothing nature type, so we have to declare variables “number1” and “number2” with the integer data type. And also, there are no passing values to the called function. That’s why we used the scanf() function in the sum() body for taking input through the user.
- This sum() function takes nothing nature type, thats why we did not use return keyword and also instead the use of “int” data type, we use “void” data type which do not return any value.
- Following the user's input, the printf() function will run, and control will once more return to the calling function.
Program Output:

2. With arguments and without return value
In these functions, called function takes arguments from the calling function.
The parameters provided in the called function are referred to as formal parameters.
The arguments used in the calling function are the actual parameters.
This function does not return any value.
Program:
#include<stdio.h>
void addition(int, int);
int main()
{
int x, y;
printf("\n Enter any desire number \n");
scanf("%d %d",&x, &y);
addition(x, y); // call by value
return 0;
}
void addition(int a, int b)
{
int c;
c = a + b;
printf("Addition of %d and %d is = %d \n", a, b, c);
}
Explanation:
- Here we declared a function “void addition(int, int),” which has two parameters of int data type.
- We defined our function as “void addition(int a, int b)”.
- We can easily see in the function definition that this function is a “takes something” type because the addition function has two formal arguments which receive the values from the calling function,
- The addition function is also a “returns nothing ” type which means this function does not return any value. For this, we used void data type.
- In the function definition, we have variable “c” with an int data type.
- The “c” variable stores the value of the sum of “a” and “b”.
- In the main() function body, we have two variables, “x” and “y,” and our calling function, “addition(x, y)”.
- As the execution starts, control goes on the main function body, printf() and scanf() function gets executed, and then execution control goes on the addition function.
- As the addition function is called by the main() function, execution control goes on the addition function body. And as the function is called, then data of the “x” and “y” variables will pass on to “a” and “b” variables.
- The addition function body will execute, and control will move back to the called function.
- We get our result of the addition of two integers.
Program Output:

3. Without arguments and with return value
In this kind of function, no value is passed from calling function to called function However, this method returns a value that is passed to the function that called it. and the return value replaces the calling function.
So, this is the function of takes nothing but return something type.
Program:
#include<stdio.h>
int addition();
int main()
{
int s;
s=addition();
printf("addition of the two integer is: %d",s);
return 0;
}
int addition()
{
int a,b,c;
printf("\n Enter any desire number \n");
scanf("%d %d",&a, &b);
c = a + b;
return c;
}
Explanation:
- Here we declared a function “int addition(),” which has no arguments in the parenthesis. But this function returns some value.
- In the addition() function body, we can see that we would not get any value from the calling function because we do not have any arguments in function parenthesis. That's why we have to take input from the user. For this, we use the scanf() function in the function body.
- We have three variables, “a”, “b”, and “c,” with the integer data type.
- We stored our addition result in the “c” variable.
- Then we use the return keyword, which returns the value of “c”. and as it returns the value of “c”, controls will move back to the calling function, which is present in the main() function body.
- In the main function body, we have one variable, “s” with the integer data type.
- “s” variable assigned with the calling function. As our control moves back to calling function, then calling function is replaced by the “c” value.
- The “c” value is assigned to the “s” variable, and with the help of the printf() function, we get our output.
Program Output:

4. With arguments and with return value
In these types of functions, we can pass the values from calling function to called function.
This function also returns some value.
The return type of return depends on the return type of function declaration.
Program:
#include<stdio.h>
int addition(int,int);
int main()
{
int x,y,s;
printf("\n Enter any desire number \n");
scanf("%d %d",&x, &y);
s=addition(x,y);
printf("addition of the two integer is: %d",s);
return 0;
}
int addition(int a, int b)
{
int c;
c = a + b;
return c;
}
Explanation:
- Here we declared a function “int addition(int, int),” which has arguments in the parenthesis and returns some value, and the return type is int.
- In the addition() function definition, we get the values of arguments which are present in the parenthesis of called function because we get the value of arguments, so in that case, we do not need any input from the user side.
- In the addition function body, we have a variable “c” with the int data type.
- We stored our addition result in the “c” variable.
- Then we used the return keyword, which returns the value of “c”. and as it returns the value of “c”, controls will move back on the calling function, which is present in the main() function body.
- In the main() function body, we have three variables “x”, “y,” and “z”.
- We take input from the user, and these values of “x” and “y” will pass on the called function arguments means these values are received by the “a” and “b” variables.
- “s” variable is assigned with the calling function “addition(x,y)”. As our control moves back to the calling function, then the calling function replace the “c” value.
- The “c” value is then assigned to the “s” variable, and with the help of the printf() function, we get our output.
Program Output:
