The Big Picture


C++, like Pascal, breaks instructions up into blocks called functions. When a program is first run, a function named "main" is executed. One big difference between Pascal and C++ is how functions are defined. Take a look at this very small program:

void main(void)
{

}

Let's go over each part. The first line, "void main(void)", is the function heading. This is the equivalent of saying "procedure main;" in Pascal. Note that there's no semicolon in the C++ version; this is because what must come immediately after main is an instruction. Of course, one instruction is not nearly enough, so we can define a block and put as many instructions as we want in it.

In the above example, the block is the area between the { and the }. The { and } are C++'s equivalents of Pascal's Begin and End -- In fact, they are nearly identical. As with Pascal, you can use the { and } to fill in as many lines as we want and have them used as one big instruction. You've probably done this with a for loop before; the for loops only want one instruction to follow it, but if you used begin and end, you could put as many instructions in the loop as you wanted.


Table of Contents

The Big Picture | Comments | Variables | More on Variables
Variable Operations | Making Choices | More on if | Using else
Using switch | The while Loop | The do..while Loop | Constants
The for Loop | More on the for Loop | Exercises