Check out example codes for "how use global variables instead of local in c++". It will help you in understanding the concepts better.

Code Example 1

using namespace std; 
int x;  // Global x 
int main() 
  int x = 10; // Local x 
  cout<<"Value of global x is "<<::x<<endl; 
  cout<<"Value of local x is "<<x;   
  return 0; 

Learn ReactJs, React Native from