... outputs this variable to show that it hides x in the outer block of main as well as the global x. When the block exits, the variable x with value 7 is destroyed automatically. Next, line 25 outputs the local variable x in the outer block of main to show that it’s no longer hidden.

Fig. 6.11 Scoping example.

Alternate View

 1   // Fig. 6.11: fig06_11.cpp
 2   // Scoping example.
 3   #include <iostream>
 4   using namespace std;
 5
 6   void useLocal(); // function prototype
 7   void useStaticLocal(); // function prototype
 8   void useGlobal(); // function prototype

Get C++ How to Program, 10/e 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.