SNS COLLEGE OF TECHNOLOGY, COIMBATORE –35
(An Autonomous Institution)
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Function Prototypes / Categories of functions
• Function with no arguments and no return values.
• Function with arguments and no return values.
• Function with arguments and return values.
• Function with no arguments and with return values.
1. Function with no arguments and no return values
In this prototype, no data transfers takes place between the calling
function and the called function. They read data values and print result in the
same block.
Example :
#include <stdio.h>
#include<conio.h>
void main() //calling function
{
void add(void);
add();
}
void add() //called function
19ITT101- Programming in C & DS By M.Karthick AP/CSE
SNS COLLEGE OF TECHNOLOGY, COIMBATORE –35
(An Autonomous Institution)
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
{
int a,b,c;
printf("\nEnter two number:");
scanf("%d%d",&a,&b);
c=a+b;
printf("\nSum is:%d",c);
}
Output:
Enter two number:3
4
Sum is:7
2. Function with arguments and no return values
In this prototype, data is transferred from the calling function to called
function.
The called function receives some data from the calling function and does
not send back any values to the calling functions. It is a one way data
communication.
Example:
19ITT101- Programming in C & DS By M.Karthick AP/CSE
SNS COLLEGE OF TECHNOLOGY, COIMBATORE –35
(An Autonomous Institution)
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
#include <stdio.h>
#include<conio.h>
void main()
{
int a,b;
void add(int,int);
printf("\nEnter two number:");
scanf("%d%d",&a,&b);
add(a,b);
}
void add(int x,int y) //function with arguments
{
int z;
z=x+y;
printf("\nSum is:%d",z);
}
Output
Enter two number:2
4
Sum is:6
3. Function with arguments and return values
In this prototype, the data is transferred between the calling
function and called function.
The called function receives some data from the calling function and send
back a value return to the calling function. It is a two way data
communication.
19ITT101- Programming in C & DS By M.Karthick AP/CSE
SNS COLLEGE OF TECHNOLOGY, COIMBATORE –35
(An Autonomous Institution)
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Example
#include <stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
int add(int,int);
printf("\nEnter two number:");
scanf("%d%d",&a,&b);
c=add(a,b);
printf("\nSum is:%d",c);
}
int add(int x,int y)
{
int z;
z=x+y;
return(z);
}
Output
Enter two number:6
7
Sum is:13
19ITT101- Programming in C & DS By M.Karthick AP/CSE
SNS COLLEGE OF TECHNOLOGY, COIMBATORE –35
(An Autonomous Institution)
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
4. Function with no arguments and with return values
The calling function cannot pass any arguments to the called function
but the called function may send some return value to the calling function. It is
a one way data communication
Example:
#include <stdio.h>
#include<conio.h>
void main()
{
int add(),d;
d=add();
printf("\nSum is:%d",d);
}
19ITT101- Programming in C & DS By M.Karthick AP/CSE
SNS COLLEGE OF TECHNOLOGY, COIMBATORE –35
(An Autonomous Institution)
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
int add() //function wit no argument
{ int a,b,c;
printf("\nEnter two number:");
scanf("%d%d",&a,&b);
c=a+b;
return(c);
}
Output
Enter two number:5
8
Sum is:13
Note:
If the return data type of a function is “void”, then, it can‟t return any
values to the calling function.
If the return data type of the function is other than void such as “int, float,
double etc”, then, it can return values to the calling function.
19ITT101- Programming in C & DS By M.Karthick AP/CSE