fig06_13.cpp

fig06_13.cpp

#include<iostream>
using namespace std;

void useLocal();
void useStaticLocal();
void useGlobal();

int x = 1;

int main()
{
	cout << "global x in main is " << x << endl;
	int x = 5;
	cout << "local x in main's outer scope is " << x << endl;


	{
		int x = 7;
		cout << "local x in main's inner scope is " << x << endl;
	}

	cout << "Local x in main's outer scope is " << x << endl;

	useLocal();
	useStaticLocal();
	useGlobal();
	useLocal();
	useStaticLocal();
	useGlobal();

	cout << "\nlocal x in main is " << x << endl;

	system("pause");
	return 0;
}

void useLocal()
{
	int x = 25;
	cout << "\nlocal x is " << x << "on entering useLocal" << endl;
	++x;
	cout << "\nlocal x is " << x << "on entering uselocal" << endl;
}

void useStaticLocal()
{
	static int x = 50;

	cout << "\nlocal static x is " << x << "on entering useStaticLocal"
		<< endl;
	++x;
	cout << "local static x is " << x << " on exiting useStaticLocal"
		<< endl;

}

void useGlobal()
{
	cout << "\nglobal x is " << x << "on entering useGlobal" << endl;
	x *= 10;
	cout << "global x is " << x << "on exiting useGlabal" << endl;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值