Our first style of function will simply perform an independent
task. It will not send or
receive any parameters and it will not return
any values. The word void appears as the
return type and the parameters.
//Example program
//Screen display shown at the right
//Prototyping, defining and calling a function
#include<iostream.h>
#include<stdlib.h>
void astericks(void);
//function prototype
int main(void)
{
system("CLS");
cout<<"Heads up, function!\n";
astericks( );
//function
call
cout<<"Again,
function!\n";
astericks( );
//function
call
cout<<"Job well done!\n";
return 0; //main( ) is over - ALL STOP!!
}
//function definition
void astericks(void)
{
int count; // declaring
LOCAL variable
for(count = 1; count<=10; count++)
cout<<"*";
cout<<endl;
return; //return value is
VOID, no return
}
|