Sunday 8 March 2015

Function Prototypes in C


Using functions in your program requires that you first declare the function (the prototype). Later you can implement the function. The prototype tells the compiler in advance about some characteristics (name of the function, return type and parameters) of a function. A function prototype takes the form:

type function-name(type argement-1, type argument-2, …..);

The function prototype is a statement that ends with a semicolon. The function name is any legal identifier followed by the function parenthesis without any space in between. The function “type” is the data type of the return value. If the function does not return a value, the data type is defined as void. The arguments (or parameters) come inside the parenthesis, preceded by their types and separated by the commas. If the function does not any parameters, it is either kept blank or the word void is used inside the parenthesises. Following are some examples for prototypes:

void exit(int x);
int kbhit( );
double power(double x, double y);

The first function returns no value and it takes an integer argument. Second prototype returns an integer value and has no inputs. Third function returns a double value and takes two double values.

No comments:

Post a Comment