Storage class in C language.

Storage class in C language.

Learn from voice....

17/01/2021 12:44PM

Episode Synopsis "Storage class in C language."

Storage class in C language. A storage class represents the visibility and a location of a variable. It tells from what part of code we can access a variable. A storage classis used to describe the.... *. The variable scope. *.The location where the variable will be stored. *. The initialised value of a variable. *. A lifetime of a variable. *.Who can access a variable? So, a storage class is used to represent the information about a variable. A variable is not only associated with a data type, its value but also a storage class. There are four storage classes Auto Extern Static Register Auto storage class. The variables defined using auto storage class are called as local variables. Auto stands for automatic storage class. A variable is in auto storage class by default if it is not explicitly specified. The scope of an auto variable is limited with the particular block only. Once the control goes out of the block, the access is destroyed. This means only the block in which the auto variable is declared can access it. A keyword auto is used to define an auto storage class. By default, an auto variable contains a garbage value. Extern storage class. Extern stands for external storage class. Extern storage class is used when we have global functions or variables which are shared between two or more files. Keyword extern is used to declaring a global variable or function in another file to provide the reference of variable or function which have been already defined in the original file. The variables defined using an extern keyword are called as global variables. These variables are accessible throughout the program. Note that the extern variable cannot be initialized it has already been defined in the original file. Static storage class. The static variables are used within function/ file as local static variables. They can also be used as a global variable. Static local variable is a local variable that retains and stores its value between function calls or block and remains visible only to the function or block in which it is defined. Static global variables are global variables visible only to the file in which it is declared. Global variables are accessible throughout the file whereas static variables are accessible only to the particular part of a code. The lifespan of a static variable is in the entire program code. A variable which is declared or initialized using static keyword always contains zero as a default value. Register storage class. We can use the register storage class when we want to store local variables within functions or blocks in CPU registers instead of RAM to have quick access to these variables. For example, "counters" are a good candidate to be stored in the register. The keyword register is used to declare a register storage class. The variables declared using register storage class has lifespan throughout the program. It is similar to the auto storage class. The variable is limited to the particular block. The only difference is that the variables declared using register storage class are stored inside CPU registers instead of a memory. Register has faster access than that of the main memory. The variables declared using register storage class has no default value. These variables are often declared at the beginning of a program.

Listen "Storage class in C language."

More episodes of the podcast Learn from voice....