O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

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

Scope

Besides the change to variable declarations, there is another slight alteration to the way that scoping for function declarations is handled. In C++, all functions must be declared before use. This means that compiling files in the correct order becomes more important, as does the inclusion of header files.

Prototyping is, however, an acceptable form of declaration, and so it is quite common to find C++ programs that are structured in the following way:

#include . . .
#define . . .
function prototypes
main function
   {
   }
function implementations

By a similar token, the declare-before-use rules for variables means that sometimes they are not available outside a code block, as you saw previously. In other words, those variable defined inside ...

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