//_34_综合实例
//_34_main.cpp
//同函数一样,外部变量的定义和外部函数的说明不同
//外部变量的定义只有一词,它的位置必须在所有函数之外
//而同一文件中的外部变量的说明可以有很多次,位置实在函数之内
//(那个函数要用到就在哪个函数中声明)
#include <stdio.h>
#include <stdlib.h>
//声明三个子函数
void head1();
void head2();
void head3();
int count=10;//全局变量
int main()
{
register int index;//定义为主函数寄存器变量
//在调用变量index时会节省很多时间
head1();
head2();
head3();
printf("the value of count is:%d\n",count);
for(index=8;index>0;index--)
{
int staff;//局部变量
//staff的可见范围只在当前函数体内
for(staff=0;staff<=6;staff++)
printf("%d ",staff);
printf("index is now %d\n",index);
}
system("pause");
return 0;
}
int counter;//全局变量,可见范围是从定义之处到源程序结尾
//三个子函数的的定义
void head1()
{
int index;//局部变量
index = 23;
printf("the head1 value(index) is %d\n",index);
}
void head2()
{
int count;//head2()的局部变量count,
//变量名与全局变量重名,
//故全局变量count不能呢挂在函数head2中使用
count = 53;
printf("the head2 value(count) is %d\n",count);
counter = 77;
}
void head3()
{
printf("the head3 value(counter) is %d\n",counter);
}
34_综合实例
最新推荐文章于 2024-04-21 12:02:37 发布