0

What is ' storage-class' ? Where is it used?

I have seen a syntax of array, where it was mentioned in the beginning. But, I don't know what exactly it is used for.

12th Sep 2019, 2:52 PM
Afzal Rahman Shaikh
Afzal Rahman Shaikh - avatar
1 Antwort
+ 1
Storage class defines lifetime and visibility of variables.. There are 4 storage classes 1. Auto 2. Static 3. Register 4. Extern (C++ adds a new storage class called Mutable) 1. Variables which we use are auto by default..Its visibility is only in the function it is declared and lifetime till the function ends. 2. Static variables are declared by usimg static keyword (static int a=10;) lifetime of static variable is throughout the program and is visible only in that particular function. Advantage of static variable is that it is initialized only once.. 3. Register variable are same as auto variables but writing register before variable declaration will tell compiler to store the variable in CPU register..So it can be accessed speedily.. 4. Extern variable are used to reference global variables declared in another programs.. This storage classes are used as per the needs of program..
12th Sep 2019, 5:47 PM
Alaska
Alaska - avatar