![]() |
#2
thames2008-08-12 12:40
#include "iostream" //头文件,不说了
using namespace std; //这一句参照http://www. int Am,An; //定义全局变量 static int ASx,ASy; //这一句在此例没有意义可以//掉 void Func1();void Func2();void Func3(); //3个函数模型 int main() { cout<<"执行过Func1() \n"; Func1(); //主函数运行到这次开始运行Func1()函数 cout<<"Am的值是:"<<Am<<endl; cout<<"An的值是:"<<An<<endl; cout<<endl; cout<<"执行过 Func2() \n"; Func2(); //此处运行Func2()函数 cout<<"Am的值是:"<<Am<<endl; cout<<"An的值是:"<<An<<endl; cout<<"执行过Func3() \n"; Func3(); //此处运行Func3()函数 cin.get(); //程序运行到这里等待输入,目的是让程序显示结果暂停,而不直接return 0结束程序使程序员来不及看结果。 return 0; } extern int Bp; //标明Bp在程序另外地方有声明,及变量调用 void Func3() //Func3()内容 { cout<<"Bp的值是:"<<Bp<<endl; cout<<endl; } int Bp; //此处声明Bp变量 extern int Am; //因为程序开始已经声明了全局变量,所以此行可以//掉 void Func1() { Bp=2; Am=8; } void Func2() { extern int An; Am+=10; An=27; } |

#include "iostream"
using namespace std;
int Am,An;
static int ASx,ASy;
void Func1();void Func2();void Func3();
int main()
{
cout<<"执行过Func1() \n";
Func1();
cout<<"Am的值是:"<<Am<<endl;
cout<<"An的值是:"<<An<<endl;
cout<<endl;
cout<<"执行过 Func2() \n";
Func2();
cout<<"Am的值是:"<<Am<<endl;
cout<<"An的值是:"<<An<<endl;
cout<<"执行过Func3() \n";
Func3();
cin.get();
return 0;
}
extern int Bp;
void Func3()
{
cout<<"Bp的值是:"<<Bp<<endl;
cout<<endl;
}
int Bp;
extern int Am;
void Func1()
{
Bp=2;
Am=8;
}
void Func2()
{
extern int An;
Am+=10;
An=27;
}
[[it] 本帖最后由 SD7436 于 2008-8-12 12:23 编辑 [/it]]