... are distinct, the program declares one variable int and the other double.

Fig. 6.19 Unary scope resolution operator.

Alternate View

 1   // Fig. 6.19: fig06_19.cpp
 2   // Unary scope resolution operator.
 3   #include <iostream>
 4   using namespace std;
 5
 6   int number{7}; // global variable named number
 7
 8   int main() {
 9      double number{10.5}; // local variable named number 
10
11      // display values of local and global variables
12      cout << "Local double value of number = " << number
13         << "\nGlobal int value of number = " << ::number << endl;
14   }

Local double value of number = 10.5
Global int value of number = 7

Good Programming Practice 6.5

Always ...

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.