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. 

  • 相关阅读:
    数组索引,内容交换
    查找两个等长升序线性表的中位数
    MarkDown使用小结
    java元注解
    LeetCode OJ:Valid Number
    LeetCode OJ:Insert Interval
    关于博客的格式
    9.Hive Metastore Administration
    3.控制hive map reduce个数
    6.capacity scheduler
  • 原文地址:https://www.cnblogs.com/dracohan/p/2937996.html
Copyright © 2011-2022 走看看