Professional Documents
Culture Documents
6.function Prototypes
6.function Prototypes
Example :
#include <stdio.h>
#include<conio.h>
void main() //calling function
{
void add(void);
add();
}
{
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
Example:
#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
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
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);
}
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.