Function Declarations


A function must be declared before it is called. A function declaration consists of a return type, the function name, and parameter list. These three elements are referred to as the function prototype. A function prototype describes the interface of the function.

Function Declarations Go in Header Files

By putting function declarations into header files, we can ensure that all the declarations for a given function agree. If the interface to the function changes, only one declaration must be changed.
The source file that defines the function should include the header that declares the function.

Default Arguments

A default argument is a value that, although not universally applicable, is the argument value that is expected to be used most of the time. When we call the function, we may omit any argument that has a default. The compiler will supply the default value for any argument we omit.

a function to create and initialize a string intended to simulate a window can provide default arguments for the height, width, and background character of the screen.

     string screenInit(string::size_type height = 24,
                       string::size_type width = 80,
                       char background = ' ' );

A function that provides a default argument for a parameter can be invoked with or without an argument for this parameter.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.