zoukankan      html  css  js  c++  java
  • C static extern和全局变量

    #include <stdio.h>
    //默认全局变量为外部变量
    int a;
    //当全局变量前面加上static时,该变量为内部变量
    static int b;
    void test();
    int main()
    {
        /*************************************************************
         * extern static和全局变量
         *   全局变量分2种:
         *      外部变量:定义的变量能被本文件和其他文件访问
         *            1、 默认情况下,所有的全局变量都是外部变量
         *            2、 不同文件中的同名外部变量,都代表着同一个变量
         *      内部变量:定义的变量只能被本文件访问,不能被其他文件访问
         *            1、 不同文件中的同名内部变量,互不影响
         *      static对变量的作用:定义一个内部变量
         *      extern对变量的作用:声明一个外部变量
         *
         *************************************************************/
         a = 20;
         b = 1000;
         test();
         return 0;
    }
    #include <stdio.h>
    int a;
    int b;
    void test()
    {
        printf("a = %d
    ", a);
        printf("b = %d
    ", b);
    }
    a = 20
    b = 0
  • 相关阅读:
    轻量级锁和偏向锁等
    桥接模式
    适配器模式
    建造者模式
    2-工厂模式
    Swift
    给视图添加点击波纹效果swift5
    Xcode 支持真机版本路径
    22个常用开源库(most swift)
    Github上关于iOS的各种开源项目集合
  • 原文地址:https://www.cnblogs.com/heml/p/3531772.html
Copyright © 2011-2022 走看看