Type 2
The second category of user defined function passes a few formal arguments to a function but the function does not return back any value to the caller. It is a one- way data communication among a calling portion of the program and the function block.
Example:
# include<iostream.h>
void main(void)
{
void power(int, int); //function declaration
int x,y;
-------
power(x,y);
}
void power(int x, int y) //function calling
{
-------
// body of the function
// there is no value transferred back to the caller
}
Sample program:
// Passing formal arguments with no return statement
// source name: funct3.cpp
# include<iostream.h>
void main(void)
{
void square ( int ); //function declaration
int max;
cout<< "enter a value for n \n";
for ( int i = 0; i <= max; i++)
square( i );
}
void square (int n)
{
float value;
value = n * n;
cout<< "i = "<< n <<"square = "<< value<< endl;
}
output of the program
enter value for n
2
i= 0 square = 0
i= 1 square = 1
i= 2 square = 4