O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Where You Put Function Code

C++ requires that you declare everything before you use it. Thus, a function must be declared before it is used in another function. Because of this, the functions called by main() are typically placed in the space above main() in C++ programs. Functions used by a function called from main() are defined above that function, as shown here:

void A(void)
{
}

void C(void)
{
}

void D(void)
{
}

void B(void)
{
    C();
    D();
}

main()
{
    A();
    B();
}

Declaring is not always the same thing as defining. Some older C and C++ programs use function prototypes to declare a function without defining it.

A prototype is a function header with no body. It ends with a semicolon. Modern programs rarely, if ever, should use a function prototype. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required