第5章程序结构 H void g( i cout<<n=<<n<<endl;) void mal f(); 程序运行结果为 这样的共享方法,使用相当方便,但是副作用也 不可低估
第5章 程序结构 void g( ) { cout<<"n="<<n<<endl; } void main( ) { f( ); g( ); } 程序运行结果为 n=5 这样的共享方法,使用相当方便,但是副作用也 不可低估
第5章程序结构 H 【例5-3】局部变量和全局变量例题 #includesiostream. h> void main( static int a tb=-10 int c=O void other(void) cout<<"----main----"<<endl
第5章 程序结构 【例5-3】 局部变量和全局变量例题。 #include<iostream.h> int i=1; void main( ) { static int a; int b= -10; int c=0; void other(void); cout<<"----main----"<<endl;
第5章程序结构 H cout<"i="<<i<<"a="<<a<<"b="<<b<"c="<<c<endl; c=c+8 other() cout<< -"<<endl cout<"i="<<<<"a="<<a<<"b="<<b<<"c="<<c<<endl; other( void other(void static int a=l
第5章 程序结构 cout<<"i="<<i<<" a="<<a<<" b="<<b<<" c="<<c<<endl; c=c+8; other( ); cout<<"----main----"<<endl; cout<<"i="<<i<<" a="<<a<<" b="<<b<<" c="<<c<<endl; other( ); } void other(void) { static int a=1;
H 第5章程序结构 static int b int c=5 1=i+2a=a+3:c=c+5 cout<< ---other----"<<endl cout<"i="<<<<"a="<<a<<"b="<<b<<"c="<<c<<endl;
第5章 程序结构 static int b; int c=5; i=i+2;a=a+3;c=c+5; cout<<"----other----"<<endl; cout<<"i="<<i<<" a="<<a<<" b="<<b<<" c="<<c<<endl; b=a; }
第5章程序结构 H 程序运行结果为 main-- i=1a=0b=-10c=0 ----other- 3a=4b=0c=10 main a=0b=-10c=8 -m--othe 5a=7b=4c=10
第5章 程序结构 程序运行结果为 ----main---- i=1 a=0 b= -10 c=0 ----other---- i=3 a=4 b=0 c=10 ----main---- i=3 a=0 b= -10 c=8 ----other---- i=5 a=7 b=4 c=10