When a function is defined after the main function it needs to be declared in the declaration section of the program. This declaration section statement is known as function prototype.
This tells the calling function the type of value that will be returned with the name of the function and list of argument data types.
Syntax:
return type function name(Argument list);
int fun (f1,f2);
/*Program to show prototype function in atomic storage class*/
#include<stdio.h>#include<conio.h>
void fun2();
void fun1()
{
int a,b,sum=0;
printf("\n enter any value of a and b");
scanf("%d%d",&a,&b);
sum=a+b;
printf("\n sum of %d and %d is %d",a,b,sum);
printf("\n");
fun2();
}
void fun2()
{
float a,b,mul;
printf("\n enter any value of a and b");
scanf("%f%f",&a,&b);
mul=a*b;
printf("\n multiplication of %f and %f is %f",a,b,mul);
}
void main()
{
char nm[200];
printf("\n enter your name");
scanf("%s",nm);
fun1();
getch();
}
/*Program to show prototype function by global declaration */
#include<stdio.h>#include<conio.h>
void fun2();
int a=10,b=20;
void fun1()
{
int sum=0;
sum=a+b;
printf("\n sum of %d and %d is %d",a,b,sum);
printf("\n");
fun2();
}
void fun2()
{
int mul;
mul=a*b;
printf("\n multiplication of %d and %d is %d",a,b,mul);
}
void main()
{
char nm[200];
printf("\n enter your favourite line");
scanf("%s",nm);
fun1();
getch();
}
No comments:
Post a Comment