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. 

  • 相关阅读:
    hdu 2586(最近公共祖先LCA)
    hdu 3394(点双连通)
    hdu 4005(边双连通)
    hdu 2460(tarjan求边双连通分量+LCA)
    【转载】8天学通MongoDB——第四天 索引操作
    【转载】8天学通MongoDB——第三天 细说高级操作
    [转载]MongoDB开发学习 经典入门
    【原创】jQuery 仿百度输入标签插件
    ★《唐琅探案》后记【2】
    ★《唐琅探案》后记【1】
  • 原文地址:https://www.cnblogs.com/dracohan/p/2937996.html
Copyright © 2011-2022 走看看