小谈static 与 extern

作者: shenyuanluo | 来源:发表于2016-08-27 20:07 被阅读79次
    //test.c    
        
    #include <stdio.h>    
        
    static int a;    // 定义内部变量
        
    void test()    
    {    
      printf("a = %d",a);    
    }
    
    
    #include <stdio.h>    
        
    extern void test();    //声明一个外部函数test,以便main.c中可以访问    
    extern int a;     //声明一个外部变量a,不是定义    
        
    int main()    
    {    
       a = 10;    //对外部变量a进行赋值    
       test();    //调用外部函数    
    
       return 0;    
    }      
    ```

相关文章

网友评论

    本文标题:小谈static 与 extern

    本文链接:https://www.haomeiwen.com/subject/wyltettx.html