Different types of function

Mainly there are 4 different categories of function in C programming
1. Void type function – Function with no argument and no return type
2. Function with argument and no return type.
3. Function with no argument and return type.
4. Function with argument and return type.

Void type function – Function with no argument and no return type

In this method there is no argument passed in the function and the return type of the function is also void.
Let’s take an example to understand it,

#include <stdio.h>
using namespace std;
void add(); // declaration of void type function function(prototype)
int main()
{
	add(); //function call
}
void add() // body of the function 
{
		float a,b,c;
	printf("\tenter two numbers to add\n\t"); 
	scanf("%f%f",&a,&b);
	c=a+b;
	printf("\t addtion is:%f",c); 
}

Function with argument and no return type

In this method, argument type is defined in the function argument and the return type of the function is void. Let’s take an example to understand it,

#include <stdio.h>
using namespace std;
void add(int); // declaration of function(prototype)
int main()
{
	
	add(88); //function call with argument and no return type

}
void add(int n) // body of the function 
{
		int a,c;
	printf("\tenter a number to add\n\t");
	scanf("%d",&a); 
	c=n+a;
	printf("\t addtion is:%d",c); 
}

Function with no argument and return type 

In this method no argument is passed in the function and the return type of the function is defined.This type of function return some value when we call the function from the main().
Let’s take an example to understand it,

#include <stdio.h>
int add(); // declaration of int type function(prototype)
int main()
{
	int k;
	k=add(); //function call with return type no argument 
    printf("\t answer is  %d",k);
}
int add() // body of the function 
{
		int a,b,c;
	printf("\tenter two numbers to add\n\t");
	scanf("%d%d",&a,&b); 
	c=b+a;
	return c;
}

Function with argument and return type 

In this method argument is passed while defining, declaring and calling the function.This type of function return some value when we pass an argument in function calling statement in main() function .
Lets take an an example to understand it, 

#include <stdio.h>
int add(int); // declaration of int type function with int type parameter(prototype)
int main()
{
	int k;
	k=add(24); /*function call with return type and argument ,
		   		 and returned value is stored in k*/
    printf("\tanswer is  %d",k);
}
int add(int x) // body of the function 
{
	int a,c;
	printf("\tenter a number to add\n\t");
	scanf("%d",&a); 
	c=a+x;
	return c;
}