The Function Definition
The function definition holds the actual code for the function.
Example: A function definition part of void starline( );
void starline( ) //function declarator
{
for (int j = 0 ; j<=45;j++) //function body cout<<"*";
cout<<endl;
}
The function body composed of the statements which make up the function, delimited via braces. The function declaration must use the similar function name, have the similar argument types in the similar order, and have the similar return type. The function declaration should not terminate along with semicolon.
Whenever the function is called the control is transferred to the first statement in the function body. Other desclaration in the function body are then executed and when closing brace encountered the control returns to the calling program.
Sample Program:
// source code defines the function calling, function declaration and function //definition
// store the file as funct1.cpp
# include<iostream.h>
void main( )
{
void show ( ); // function declaration
show( ); // function calling
}
void show ( ) // function definition
{
cout<< " this is a test program \n";
cout<<" elaborate a function call \n";
cout<< " in C++ \n";
}
Output of the program
this is a test program
elaborate a function call
in C++
The function main invokes the display ( ) function. Within C++ every function is almost a separate program. A control will be transferred from the main function or from a function to a called function. Following it has executed all the statements in the function and then the control switches back to the calling portion of the program.