C – Function Types

After reading this function types topic, you will know the function types, you will understand its theory and examples also you will able to implement function types in C programming.

A user-defined function classified as:

  • Function with no argument pass and no return value.
  • Function with argument pass and no return values.
  • Function with argument pass and return values.
  • Function with no argument pass and return values.

Function with no argument pass and no return values

In this type of function, we cannot pass any data to calling function as well as cannot receive any data from the calling function. The example below will show the way of writing this type of function in C programming.
Example:
Program (1): To demonstrate the Function with no argument pass and no return value.

#include<stdio.h>
#include<conio.h>
void main(void)
{
void add(void);
add();             //function add() not pass any argument(or data) to calling function
getch();
}
void add(void)   //void in beginning indicate function add(void) not return any value
{
int a,b,sum;
printf("Enter two numbers :- ");
scanf("%d %d",&a,&b);
sum=a+b;
printf("the add is %d",sum);
return;
}

Output (1)

Enter two numbers :- 2
5
the add is 7

Function with argument and no return values

In this type of function, we can only pass any data to calling function. This function also referred as one-way data communication. The example below will show the way of writing this type of function in C programming.
Example:
Program (1): To demonstrate the Function with argument pass and no return value.

#include<stdio.h>
#include<conio.h>
void main(void)
{
int a,b;
void add(int,int);
printf("Enter two numbers :- ");
scanf("%d %d",&a,&b);
add(a,b);                     //function add(a,b) passes arguments(or data) to calling function
getch();
}
void add(int c,int d)            // void indicate function add(int c,int d) not return any value
{
int sum;
sum=c+d;
printf("the add is %d",sum);
return;
}

Output (1)

Enter two numbers :- 2
5
the add is 7

Function with argument and return values

In this type of function, we can pass any data to calling function as well as can receive any data from the calling function. This function also referred as two-way data communication. The example below will show the way of writing this type of function in C programming.
Example:
Program (1): To demonstrate the Function with argument pass and return value.

#include<stdio.h>
#include<conio.h>
void main(void)
{
int a,b,sum;
int add(int,int);            //function add(int,int) passes arguments(or data) to calling function
printf("Enter two numbers :- ");
scanf("%d %d",&a,&b);
sum=add(a,b);
printf("the add is %d",sum);
getch();
}
int add(int x,int y)       //int in beginning indicate function add(int x,int y) return integer value
{
return(x+y);
}

Output (1)

Enter two numbers :- 2
5
the add is 7

Function with no argument pass and return values.

In this type of function, we cannot pass any data to calling function but can receive any data from the calling function. The example below will show the way of writing this type of function in C programming.
Example:
Program (1): To demonstrate the Function with no argument pass and return value.

#include<stdio.h>
#include<conio.h>
void main(void)
{
int add(void);
int sum;
sum=add();     //function add() not passes arguments(or data) to calling function
printf("the add is %d",sum);
getch();
}
int add(void)     //int indicate function add(void) return integer value
{
int a,b;
printf("Enter two numbers :- ");
scanf("%d %d",&a,&b);
return(a+b);
}

Output (1)

Enter two numbers :- 2
5
the add is 7

Published by

Electrical Workbook

We provide tutoring in Electrical Engineering.

Leave a Reply

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