Programmer-Defined Functions

  1. A programmer can create their own functions.

  2. Description of the function is usually placed in the same file as the main part of the program.

  3. Once the function is properly described, it can be used like the predefined functions.

  4. Description of the function comes in 2 parts:

  5. Either the function definition or the function prototype must appear before the function is called.

    Some people place the function definition before the main part of the program. In that case there is no need to include the function prototype.

    However the recommended style is to place all the function prototypes before the main program but after the preprocessor directives. The function definitions should appear after the main program. The specific order in which they appear does not matter at all.

  6. The main program is actually a function itself. It is somewhat special because it is the one called by the operating system when you run your program. This is why there can only be one such function, its name cannot be changed and must be called main.

  7. A function is called or invoked by using its name and a list of its arguments enclosed in parentheses. The argument list consists of arguments separated by commas.

  8. The actual arguments supplied to the function when it is called, can be literal constants, variables or expressions, as long as their types agree with those assumed of the function arguments.