Different categories of function:
1) Function with no arguments and no return value.
2) Function with arguments and no return value.
3) Function with no arguments and return value.
4) Function with arguments and return value.
1) Function with no arguments and no return value:
This category of function cannot return any value back to the calling program and it does not accept any arguments also. It has to be declared as void.
For example:
void add()
{
inta,b,c;
a=5;
b=6;
c=a+b;
printf(“%d”,c);
}
It should be called as add();
2) Function with arguments and no return value:
This category of function cannot return any value back to the calling program but it takes arguments from calling program. It has to be declared as void. The number of arguments should match in sequence, number and data type.
For example:
void add(intx,int y)
{
int z;
z=x+y;
printf(“%d”,z);
}
It should be called as add(4,5); where x will take 4 and y will take 5 as their values.
3) Function with no arguments and return value:
This category of function can return a value back to the calling program but it does not take arguments from calling program. It has to be declared with same data type as the data type of return variable.
For example:
int add()
{
inta,b,c;
a=5;
b=6;
c=a+b;
return(c);
}
It should be called as int x = add(); where x will store value returned
by the function.
4) Function with arguments and return value:
This category of function can return a value back to the calling program but it also takes arguments from calling program. It has to be declared with same data type as the data type of return variable.
For example:
int add(intx,int y)
{
int z;
z=x+y;
return(z);
}
It should be called as int s = add(4,5); where x will have 4 and y will have 5 as their values and s will store value returned by the function.