第9篇存储属性.pptVIP

  • 2
  • 0
  • 约1.29万字
  • 约 63页
  • 2017-06-02 发布于湖北
  • 举报
【例9.5】 用extern声明本文件定义的外部变量来扩大外部变量的作用域。 #include stdio.h void main( ) { void swap( ); /* 函数声明 */ extern int x,y; /* 全局变量声明 */ printf(请输入x=?,y=?\n); scanf(x=%d,y=%d,x,y); swap( ); printf(x=%d,y=%d\n,x,y); } int x,y; void swap( ) { int t; t=x; x=y; y=t; return; } 程序运行情况: 请输入x=?,y=? x=6,y=8 x=8,y=6 【例9.6】 用extern声明其他文件的外部变量来扩大外部变量的作用域。 /* C 源程序文件D:\f1.c的内容 */ #include stdio.h #include D:\f2.c int x; /* 外部变量定义 */ void main( ) { int sum,y; printf(y=?\n); scanf(y=%d,y); store( ); sum=x+y; printf(sum=%d\n,sum); } /* C 源程序文件d:\f2.c的内容 */ exte

文档评论(0)

1亿VIP精品文档

相关文档