ROHINI COLLEGE OF ENGINEERING AND TECHNOLOGY
FUNCTION PROTOTYPE
Function prototype is a declaration statement that identifies function with function name,
data type, a list of a arguments. All the function need to be declared before they are used. (i.e.
called)
Syntax:
returntype functionname (parameter list);
Return type – data type of return value. It can be int, float, double, char, void etc.
Function name – name of the function
Parameter type list –It is a comma separated list of parameter types.
Example:
int add(int a, int b);
Function declaration must be terminated with a semicolon(;).
Types of function prototypes:
1. Function with no arguments and no return values
2. Function with arguments and no return values
3. Function with arguments and one return values
4. Function with no arguments and with return values
Prototype 1: Function with no arguments and no return values
This function doesn‟t accept any input and doesn‟t return any result.
These are not flexible.
Program
#include<stdio.h>
#include<conio.h>
void show(); //function prototype
void main()
{
show( ); //function call
getch();
}
CS8251 PROGRAMMING IN C
ROHINI COLLEGE OF ENGINEERING AND TECHNOLOGY
void show( ) //function definition
{
printf(“Hai \n”);
}
Output:
Hai
Prototype 2: Function with arguments and no return values
Arguments are passed through the calling function. The called function operates on the
values but no result is sent back.
Program
#include<stdio.h>
#include<conio.h>
void show(int);
void main()
{
int a;
printf(“Enter the value for a \n”);
scanf(“%d”, &a);
show(a);
getch();
}
void show(int x)
{
printf(“Value =%d”, x);
}
Output:
Enter the value for a: 10
Value = 10
Prototype 3: Function with arguments and return values
Arguments are passed through the calling function
The called function operates on the values.
CS8251 PROGRAMMING IN C
ROHINI COLLEGE OF ENGINEERING AND TECHNOLOGY
The result is returned back to the calling function.
Program
#include<stdio.h>
#include<conio.h>
float circlearea(int);
void main()
{
int r;
float area;
printf(“Enter the radius \n”);
scanf(“%d”,&r);
area=circlearea(r);
printf(“Area of a circle =%d\n”, area);
getch();
}
int circlearea(int r1)
{
return 3.14 * r1 * r1;
}
Output:
Enter the radius
2
Area of circle = 12.000
Prototype 4: Function with no arguments and with return values
This function doesn‟t accept any input and doesn‟t return any result.
The result is returned back to the calling function.
Program
#include<stdio.h>
#include<conio.h>
float circlearea();
void main()
CS8251 PROGRAMMING IN C
ROHINI COLLEGE OF ENGINEERING AND TECHNOLOGY
{
float area;
area=circlearea();
printf(“Area of a circle =%d\n”, area);
getch();
}
int circlearea()
{
int r=2;
return 3.14 * r * r;
}
Output:
Enter the radius
2
Area of circle = 12.000
CS8251 PROGRAMMING IN C