CATEGORY OF FUNCTIONS : A function, depending on whether arguments are present or not and
whether a value is returned or not. The following are the function prototypes.
1 : Functions with no Parameters and no Return Values.
2 : Functions with no Parameters and Return Values.
3 : Functions with Parameters and no Return Values.
4 : Functions with Parameters and Return Values.
1 : Functions with no Parameters and no Return Values :
1 : In this category, there is no data transfer between the calling function and called function.
2 : But there is flow of control from calling function to the called function.
3 : When no parameters are there , the function cannot receive any value from the calling function.
4: When the function does not return a value, the calling function cannot receive any value from the called
function.
Ex #include<stdio.h>
#include<conio.h>
void sum();
void main()
{
sum();
getch();
}
void sum()
{
int a,b,c;
printf("enter the values of a and b");
scanf("%d%d",&a,&b);
c=a+b;
printf("sum=%d",c);
}
2 : Functions with no Parameters and Return Values.
1 : In this category, there is no data transfer between the calling function and called function.
2 : But there is data transfer from called function to the calling function.
3 : When no parameters are there , the function cannot receive any values from the calling function.
4: When the function returns a value, the calling function receives one value from the called function.
Ex : #include<stdio.h>
#include<conio.h>
int sum();
void main()
{
int c;
clrscr();
c=sum();
printf("sum=%d",c);
getch();
}
int sum()
{
int a,b,c;
printf("enter the values of a and b");
scanf("%d%d",&a,&b);
c=a+b;
return c;
}
3 : Functions with Parameters and no Return Values.
1 : In this category, there is data transfer from the calling function to the called function using parameters.
2 : But there is no data transfer from called function to the calling function.
3 : When parameters are there , the function can receive any values from the calling function.
4: When the function does not return a value, the calling function cannot receive any value from the called
function.
Ex : #include<stdio.h>
#include<conio.h>
void sum(int a,int b);
void main()
{
int m,n;
clrscr();
printf("Enter m and n values:");
scanf("%d%d",&m,&n);
sum(m,n);
getch();
}
void sum(int a,int b)
{
int c;
c=a+b;
printf("sum=%d",c);
}
4 : Functions with Parameters and Return Values.
1 : In this category, there is data transfer from the calling function to the called function using parameters.
2 : But there is no data transfer from called function to the calling function.
3 : When parameters are there , the function can receive any values from the calling function.
4: When the function returns a value, the calling function receive a value from the called function.
Ex :
#include<stdio.h>
#include<conio.h>
int sum(int a,int b);
void main()
{
int m,n,c;
clrscr();
printf("Enter m and n values");
scanf("%d%d",&m,&n);
c=sum(m,n);
printf("sum=%d",c);
getch();
}
int sum(int a,int b)
{
int c;
c=a+b;
return c;
}