注册 登录
编程论坛 C++教室

请帮忙解释下程序,本人是初心者

SD7436 发布于 2008-08-12 11:12, 579 次点击
程序无误,只是本人不理解,还请各位帮忙解释下,麻烦大家了
#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]]
5 回复
#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;
}
#3
SD74362008-08-12 13:21
十分感谢2楼的朋友,真是非常感谢
#4
elegant872008-08-12 13:46
建议将#include "iostream"换为#include<iostream>
#5
TYFY2008-08-12 23:55
ls方法的能加快速度。。。
#6
SD74362008-08-13 11:10
是不是在实际运用中,速度的快慢是很明显,也是很必要的?
1