Advanced PIC Microcontroller Projects in C: From USB to RTOS with the PIC18F Series

A function is a self-contained section of code written to perform a specifically defined action. Functions are usually created when a single operation must be performed in different parts of the main program. It is, moreover, good programming practice to divide a large program into a number of smaller, independent functions. The statements within a function are executed by calling (or invoking) the function.
The general syntax of a function definition is shown in Figure 4.1. The data type indicates the type of data returned by the function. This is followed by the name of the function and then a set of parentheses, within which the arguments, separated by commas, are declared. The body of the function, which includes the function's operational code, is written inside a set of curly brackets.
type name (parameter1, parameter,.....) { ......... function body ......... } In the sample function definition that follows, the function, named Mult, receives two integer arguments, a and b, and returns their product. Note that using parentheses in a return statement is optional:
<b class="bold">int</b> Mult(int a, int b){ return (a*b);} When a function is called, it generally expects to be given the number of...