C ++ keyword

xiaoxiao2021-03-06  13

C keyword (static / register / atuo / extern / volatile / const) Release dev.9cbs.net/develop/Article/21/21103.shtmlhb @ 2004-09-19 10:58 C Keywords (static / register / atuo / extern / volatile / const) Doubt Social BLOG keyword STATIC Register atuo Extern Volatile Const Source of C is often dealing with us, and we often have a vague, this article The learning experience is summarized, in order to achieve the purpose of truly understanding and use. Static L Static variable scope In one file, the program is assigned a space, the space is released, and the space is released by default to 0, and its value can be changed when used. l Static variables or static functions, that is, only code within this document can access it, its name (variable name or function name) is invisible in other files. l The value of static variables generated in the function can only maintain int max_so_far (int curr) // to today (this call) so far {static int biggest; // This variable keeps the latest time Value, its validity period equal to the validity period of the entire program If (curr> biggest) Biggest = Curr; Return Biggest;} l The member variable of the C class is declared as static (called static member variable), meaning it for this class All instances are shared, that is, when a class instance modifies the static member variable, its modified value is seen by all other instances of the class; the static member function of the class can only access static members (variables or functions ). The static member variable of the L class must be initialized within the scope of its file, and the private type is no exception. For example, float savingsaccount :: currentrate = 0.00154; (Note: Currentrate is a static member variable of class savingsaccount) Register L is called the register variable with the register declared, which will be stored directly in the machine's register; but The 32-bit compiler does not work, when Global Optimizations is open, it will choose whether to put it in its own register; but other symbols related to the Register keyword are valid. Auto L It is a storage type identifier that indicates that the variable (automatic) has a local range, a variable declaration of block range (such as a variable declaration in the FOR cycle) defaults to the auto storage type. Extern 1 declares that variables or functions are external links, that is, the variable or function name is visible in other files. The variable (external variable) of its modified variable (external variable) is a static allocation space, that is, the program starts to assign, and release it at the end. Use their declared variables or functions to be defined elsewhere else or otherwise elsewhere (implementation). Declaring a variable or function default to the file can be used outside.

转载请注明原文地址:https://www.9cbs.com/read-50878.html

New Post(0)