What are storage class specifiers?
when we talk about Storage classes in C++ we are usually talking either about extern or static. The four Storage Class specifiers are as the following:
extern, static, register, auto
extern is used for global variables during seperate compilation. When used the compiler doesn't create storage for the variable when it sees it again.
static local variables retain their values within the function that they are declared between calls but are unknown to the rest of the program (unlike globals). they are very important for making stand-alone functions.
static global variables: When static is used on a global variable, it makes the variable known only to the file in which it is declared.
register is used for variables that are heavily used and tell the compiler to hold the value inside a register (although this does not actually happen with moden computer systems). register variables cannot be declared as globals and can only be local.
In summary the static keyword lets you hide portions of your program from other portions which is very handy for large and complex programs.
extern, static, register, auto
extern is used for global variables during seperate compilation. When used the compiler doesn't create storage for the variable when it sees it again.
static local variables retain their values within the function that they are declared between calls but are unknown to the rest of the program (unlike globals). they are very important for making stand-alone functions.
static global variables: When static is used on a global variable, it makes the variable known only to the file in which it is declared.
register is used for variables that are heavily used and tell the compiler to hold the value inside a register (although this does not actually happen with moden computer systems). register variables cannot be declared as globals and can only be local.
In summary the static keyword lets you hide portions of your program from other portions which is very handy for large and complex programs.

0 Comments:
Post a Comment
<< Home