This section contains 816 words (approx. 3 pages at 300 words per page) |
A function is a self-contained block of code that performs a set of actions and returns a value of a known type. It is possible, but not always necessary, to pass variables into a function and have the function operate on them (even change them); it is also possible in most common computer languages to have functions that return a "void" type, which is effectively no return value at all. The chief advantage of a function is that it can be treated as a "black box" that takes a set of known inputs and produces a corresponding output.
Languages differ, but a typical function declaration and definition in C would look something like this:
- int timeEgg(int t)
- {
- /* do some boiling, say. For t seconds */
- ringBell(); /* ring the bell */
- return t; /* returns how long it boiled for */
- }
The function above, timeEgg(), is said to take a...
This section contains 816 words (approx. 3 pages at 300 words per page) |