Procedures/Functions


You may have been wondering what the "void" thing means. In fact, you probably were wondering what the deal with "main" is. Man, do we have to answer everything for you? ;)

C++ gets rid of the "function or procedure" decision entirely -- since they're almost the same anyway, C++ just has one! Call it a function or a procedure, it's really not important; for our purposes, though, we'll call them functions. You've already seen this piece of code from the last chapter :

void main(void)
{
    cout << "Hello World!\n";
}

Let's start off with the first line, which defines the function (or procedure) "main":

void main(void)

Here's how that statement works. The first word, "void", describes what the function returns. "void" is a term C++ uses to say "nothing"; when you use void, it's a lot like procedures, as nothing is returned. If you wanted to have the function return an integer, you would say something like:

int main(void)


Table of Contents

Procedures/Functions | Returning Values | Passing Variables | Using Functions
Function Overloading | Default Parameters | Exercises