// C2_8.cpp : Defines the entry point for the console application. // 區域變數與全域變數 #include "stdafx.h" #include using namespace std; int value1 = 11; // 全域變數值 int main(int argc, char* argv[]) { int value1 = 60; int value3 = 80; cout << endl << "範圍外 value1 = " << value1 << endl; cout << "全域鸞數 value1 = " << ::value1 // 於範圍外 << endl; { // 新範圍開始 int value1 = 200; //隱藏外部的 value1 int value2 = 300; cout << endl << "範圍內 value1 = " << value1 << endl; cout << "全域鸞數 value1 = " << ::value1 //範圍內使用全域鸞數 << endl; value1 += 7; //影嚮範圍內的 value1 value3 += value2; } // 範圍結束 cout << endl << "範圍外 value1 = " << value1 << endl << "範圍外 value3 = " << value3 << endl; return 0; }