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. ...
Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.