Scope
Storage Class
//static
#include <iostream>

static int count = 0;

void increase()
{
	static int index = 0;
	index++;
	count++;
	std::cout<<index<<" "<<count<<std::endl;
}

int main(int argc, char *argv[])
{
	increase();
	increase();

	return 0;
}
			
//util.h
#ifndef UTIL_H
#define UTIL_H

extern const float pi;

float getArea(int r)
{
	return pi*r*r;
}
#endif

//main.cpp
#include <iostream>
#include "util.h"

extern const float pi = 3.14;

int main(int argc, char *argv[])
{
	std::cout<<pi<<std::endl;
	std::cout<<getArea(10)<<std::endl;

	return 0;
}
		
#include <iostream>
#include <string>

class Customer
{
	private: 
		mutable std::string name;
	public:
		Customer(std::string n):name(n){}

		void changeName(std::string n) const
		{
			name = n;
		}

		std::string getName() const {return name;}
};

int main(int argc, char *argv[])
{
	Customer c("Lin Chen");
	c.changeName("Yanhua Feng");

	std::cout<<c.getName()<<std::endl;

	return 0;
}
	
Local Scope
#include <iostream>

int main(int argc, char *argv[])
{
	int a = 0;

	{
		int b = 10;
		std::cout<<a<<" "<<b<<std::endl;
	}

	std::cout<<a<<std::endl;
	//std::cout<<b<<std::endl;//error

	return 0;
}
			
Shadowing
#include <iostream>

int main(int argc, char *argv[])
{
	int a = 0;

	{
		int a = 10;
		std::cout<<a<<std::endl;
	}

	std::cout<<a<<std::endl;

	return 0;
}
			
Global Scope
#include <iostream>

int count = 0;

void increase()
{
	count++;
	std::cout<<"Global variable: "<<count<<std::endl;
}

int main(int argc, char *argv[])
{
	increase();

	int count = 10;//shadow the global variable
	std::cout<<"Local variable: "<<count<<std::endl;
	std::cout<<"Global variable: "<<::count<<std::endl;

	return 0;
}
			
Function Linkage
File Scope and Global Scope
Reference