©1994-2003 Kevin Boone
Home     Section index     K-Zone home C++ tutorial (under construction)

Site search

Glossary
Confused by computer jargon? Look it up!

Shameless plug


Now available!

Articles
- Ten-minute guide to setting up a WAP site

- Talk like your boss: new developments in managerese

More...

Development
File handling in the Linux kernel

Java development for the Sony-Ericsson P800

SunONE Application Server 7 FAQ

More...

Linux
Using Linux with the Treo 600

- Linux on the Tecra M1

- Some notes on openzaurus

More...

Download
Java stuff

Linux stuff

More...

(Please read the download policy)

Home automation
The X10 system

Linux TW723 driver

More...

The K-Zone
K-Zone computing

K-Zone law

K-Zone education and science

K-Zone motorcycles

K-Zone DIY

K-Zone railways

K-Zone martial arts

About the author

K-Zone home page

 
layout
contents
define functions
C++ tutorial: functions


Functions are the basic organizing unit in C programs
No practical C/C++ program is simple enough for its entire operation to be contained within the 'main' function, as the previous examples have been. It is now time properly to introduce the idea of functions: the basic unit of organization in C programs. In C++, a higher-level unit of organization is introduced: the class. This does not mean that functions are unimportant: quite the opposite is the case.

So what is a function? It is simply a self-contained piece of program with certain inputs and outputs. When a function is activated it is said to be called. Functions can call other functions, so in effect a complex job can broken into progressively smaller, simpler ones. This principle is called stepwise refinement.

If you have been following the example used so far, you may have noticed functions being introduced without much comment. For example, in welcome2.cpp, a trivial procedure was divided into two even more trivial functions. Before starting a description of how to define more useful functions, we will have a look at some of the built-in functions provided in the 'standard library'.