next up previous contents index
Next: Headers and Pre-Processing Up: More About C++ Previous: Overloading   Contents   Index

Scope

A C++ statement ends with a semicolon. A collection of statements enclosed by curly braces is a ``code block'', and may be viewed as a single logical statement. Curly braces determine a ``scope'', inside of which variable names may be re-used without ambiguity. A variable defined between curly braces is said to be local (to the scope in which it is defined); its value cannot be used out of scope.

Function bodies are code blocks, as are the alternatives associated to control statements. The compiler is not picky about spaces, tabs, and newlines, so an input file should be organized in a way that makes the file easy to read. Indentation signifies levels of nesting within code blocks, but specific details are the focus of passionate debate. As with variable naming, clarity and consistency are the important criteria.



Andrew D. Hwang 2004-09-04