zoukankan      html  css  js  c++  java
  • 【C】external/internal/static/register variable and function

     external(global)

     external variable is defined outside of functions. They are available to all the below functions and all of reference points to the same instance. 

     Unlike variable, functions are all external because C don't allow define function inside another. 

     If they are referred before it's defined or it's defined in different file, extern keyword should be used. Like:

    In file1:
        extern int sp;
        extern char var [];
    
        void pushvar(double f) {...};
        void pop(void) {...};
    
    In file2:
        int sp =0;
        char var[MAXNUM];
    

      

    internal(local)

    internal variable are also called automatic variable. They're defined in functions,  come to existence when the function is entered and disappear when left. 

    static

    static keyword could be applied to:

    1, external var. In this case, the scope of var is limited to the rest of the current complied file.Without external keyword, variable wlll be seen from the whole program.

    2, internal var. In this case, var is not destroyed after function exit. It could be used to save value between different times of function invoke.

    3, function. In this case , function scope is limited to the rest of the current compiled file, just like external var. 

    Register

    Register keyword imply that this variable is heavily used. Register keyword can only be applied to automatic variable.  

    PS: external and static var has to be intialized by constant expression while automatic and register var  has no such restiction. If absence of explicit initialization, external and static var is initialized to 0, automatic and register var have undefined values. 

  • 相关阅读:
    性能测试
    怎样开始用selenium进行自动化测试
    手机自动化测试的原理
    黑盒测试与白盒测试的区别
    白盒测试方法
    黑盒测试概念及设计方法
    接口测试的概念及常用方法
    运用c语言和Java写九九乘法表
    appium键值对的应用
    压力测试和负载测试的区别
  • 原文地址:https://www.cnblogs.com/dracohan/p/2937996.html
Copyright © 2011-2022 走看看