fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int x = 10; // global
  5.  
  6. int main() {
  7.  
  8. cout << x <<endl;
  9. int x = 100; // local
  10. cout << x << endl; // 區域變數優先於全域變數
  11. // 區域變數遮蔽全域變數 (shadow effect)
  12. return 0;
  13.  
  14. }
Success #stdin #stdout 0.01s 5524KB
stdin
Standard input is empty
stdout
10
100