例5-1
题目:作用域实例
clude <iostream> using namespace std; int i; int main#in() { i=5; { int i; i=7; cout<<"i="<<i<<endl; } cout<<"i="<<i<<endl; return 0; }
例5-12
题目:变量的生存期与可见性
代码部分:
#include<iostream> using namespace std; int i=1; void other(){ static int a=2; static int b; int c=10; a+=2; i+=32; c+=5; cout<<"---OTHER---"<<endl; cout<<"i:"<<i<<"a:"<<a<<"b:"<<b<<"c:"<<c<<endl; b=a; } int main() { static int a; int b=-10; int c=0; cout<<"---MAIN---"<<endl; cout<<"i:"<<i<<"a:"<<a<<"b:"<<"c:"<<c<<endl; c+=8; other(); cout<<"---MAIN---"<<endl; cout<<"i:"<<i<<"a:"<<a<<"b:"<<b<<"c:"<<c<<endl; i+=10; other(); return 0; }
标签:cout,19,namespace,int,static,using,打卡 From: https://www.cnblogs.com/xuechenhao173/p/17414412.html