What are the different types of storage class?



Suraj Said

+0 -0

In C, there are four types of storage class specifiers:
auto: The default storage class for all local variables. An auto variable is created when a function is called and destroyed when the function exits.
register: A variable declared with the register storage class is stored in a register of the CPU, rather than in main memory. This can improve performance, but the number of registers is limited, so not all variables can be stored in a register.
static: A variable declared with the static storage class retains its value between function calls and is initialized only once, when the program starts.
extern: A variable declared with the extern storage class is defined in one source file and can be accessed by functions in other source files. The variable is not initialized when the program starts and must be defined elsewhere.



Vikas Said

+0 -0

Auto: Defines local variables, automatically allocates and deallocates memory within block scope.
Static: Maintains variable value between function calls, allocates memory at program start, retains until termination.
Register: Suggests storing variables in CPU registers for faster access, now often optimized by compilers.
Extern: Declares global variables accessible across multiple files, memory allocated and deallocated at program start and end.



Ayush Said

+0 -0

auto: The default storage class for local variables; variables exist within the block they're declared and destroyed upon block exit.
register: Suggests the compiler store the variable in a CPU register for faster access; the compiler may or may not honor this request.
static: Gives a variable block scope with a lifetime lasting the entire program (or file scope when outside functions).
extern: Declares a variable that is defined in another file or module, providing a linkage to the external variable.



Submit Your Response