Documente Academic
Documente Profesional
Documente Cultură
The storage class specifiers are used to change the way of creating the memory
storage for the variables.
auto:
This auto specifier tells the compiler that the variable declared will go out of
scope once the program exits from the current block. The program block can be
a function, a class or a structure.
This is the most widely used and non-used storage class specifier in C++.
Because, all the variables declared in C++ are of the type auto by default. So no
one need to worry about specifying this one. The declarations,
auto int var1; // declared with auto specifier for the c++ tutorial
int var1; //declared without the storage class specifier
static:
This static specifier when used will preserve the value for a particular variable
upon re-entry into the same function. For example
void static_function_example()
{
static int x = 0; //variable for C++ tutorial example
x++;
cout << x <<endl;
}
If this function is called 10 times, the output will be 1,2,3,4..etc., The value of
the variable x is preserved through function calls.
extern:
This register keyword tells the C++ compiler to allocate some storage in the
registers. Any operations using the register is bound to be the fastest. But a
mere specification of register keyword won't get the variable a place in the
register. If the compiler finds no space in the register, it'll use the cache memory
also.