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

Variable Scoping

One important side effect of grouping statements between braces is that the code defined within the braces is relevant only to other code also between the braces. This is called scoping and is of particular interest when defining variables that can be used by the code.

Recall that variables are places to store information. Local variables are relevant right now, and global variables are relevant to the whole program. The scope of a global variable is the whole source file in which it appears.

However, a variable that is declared inside a code block may be used only inside that code block or any other code blocks that might exist within it. It is said to be local.

The variable cannot be used in other code blocks that are not ...

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