Search This Blog

Saturday, September 6, 2008

What is a function prototype?

First of all, let us define what a function is - A function is a piece/block of code which performs some specific task or functionality(hence the name function). A function is identified by a function name. A function is called or invoked from another module. At this stage, the function is passed some input values(called arguments). Often, the function would also return a value back to the calling module. Hence, to the outside world, the function appears as DATA TYPE OF THE RETURNED VALUE - FUNCTION NAME - (LIST OF ARGUMENTS WITH THEIR DATA TYPES)
Ex. If a function F accepts two integers, adds them and returns a value, it would be defined as follows:
//Function definition
int F(int a, int b){
- CODE which implements the functionality;
return result
}
The line of code which is written merely to convey the list of inputs/ arguments accepted and the return type along with function name so that the function can be invoked by other modules is called the function prototype.For the above code, the prototype would be:int F(int a, int b);
The prototype would precede the function definition.

No comments:

 
ss_blog_claim=610c329374fdaea5e07dfca1c6dffb2d