C语言误区

int date[10] ; //定义一个字长10的数组,从date[0]....date[9]

 

static   char   c ;   //静态变量(有静态外部变量和静态局部变量),静态外部变量和外部变量的主要区别是静态外部变量只能在所定义的文件使用,

        //具有局部可见性;外部变量可以被其他文件使用,具有全局性。  

const char i=10;   //定义不可变的常量

 

 

extern   int  z  ;      //外部变量扩展

 

例子:

#include <stdio.h>

int  x=100;

float  y=123;

extern  int  z;   //外部变量z作用域扩展

void fun1()

{

  printf("x=%d ",x);

  printf("y=%d ",y);

}

 

void fun2()

{

  printf("x=%d ",x);

  printf("z=%d ",z);

}

void main()

{

  fun1();

  fun2();

  printf("z=%d ",z);

}

int z=1;

程序分析:外部变量z定义在main()函数之后,在函数fun1()的上边对其作用域进行扩展,

所以z的作用域变成从扩展的位置到结束;如果将语句 extern  int  z ; 拿到fun1()中,则z的

作用域就从定义的位置到文件结束再加上扩展的fun1()函数内。

原文地址:https://www.cnblogs.com/hezhangyear/p/4039977.html