Function Prototyping

Function prototyping is one of the majore improvements added to C++ function. The prototype describes the function interface to the compiler by giving details such as the number and type of arguments and the type of return values. With function prototyping, a template is always used when declaring and defining a function. When function is called, the compiler uses the template to ensure that proper arguments are passed, and the return value is treated correctly. Any violation in matching the arguments or the return types will be caught by the compiler at the time of compilation itself. These checks and controls did not exist in the conventional C function.

Function prototype is a declaration statement in the calling program and is of the following form:
type function-name (argument-list);
The argument-list contains the types and names of arguments that must be passed to the function.

Example:
float volume (int x, float y, float z);

No comments:

Post a Comment