storage class
storage class
any variable or function in the C program. These storage classes deal with
features such as scope, lifetime, and visibility that help programmers to
define a particular variable during the program’s runtime. The data type
precedes these storage classes that they had to modify.
Auto comes by default with all local variables as its storage class. The
keyword auto is used to define this storage class explicitly
The above example has a variable name roll with auto as a storage class.
This storage class can only be implemented with the local variables.
This storage class is implemented for classifying local variables whose value
needs to be saved in a register in place of RAM (Random Access Memory).
This is implemented when you want your variable the maximum size
equivalent to the size of the register. It uses the keyword register.
Register int counter;
// loop body
This storage class uses static variables that are used popularly for writing
programs in C language. Static variables preserve the value of a variable
even when the scope limit exceeds. Static storage class has its scope local to
the function in which it is defined. On the other hand, global static variables
can be accessed in any part of your program. The default value assigned is
‘0’ by the C compiler. The static keyword used to define this storage class.
The extern storage class is used to feature a variable to be used from within
different blocks of the same program. Mainly, a value is set to that variable
in a different block or function and can be overwritten or altered from within
another block. Hence it can be said that an extern variable is a global
variable that is assigned with a value that can be accessed and used within
the entire program. Moreover, a global variable can be explicitly made an
extern variable by implementing the keyword extern preceded the variable
name.
Int val;
Main()
Val = 10;
funcExtern();
Another example:
#include <stdio.h>
Extern int val; // now the variable val can be accessed and used from
anywhere
Void funcExtern()