Saturday, June 30, 2018

C programming storage classes



C storage class is another topic in C language. Here you will learn C storage class specifiers. Even you will know C variable storage class. In addition, you will have idea about C storage class and memory. However, do not forget to practise C storage classes with example exercises. You can keep reading to know more about it.

What is storage class in C language?



In C programming language, storage class is scope or visibility of variables. Furthermore, life of

 variables and or functions is storage class. You must remember that storage classes come before 

type. Because type will change them.


Types of storage classes in C programming language

auto storage class in C

The auto storage class is default storage class. It applies to all local variables. However, there is difference between auto and static storage class in C language.
Example program

Define static storage class in C programming language

On the other hand, static storage class will instruct compiler to place local variable in existence. This is for life time of a program. Moreover, destroying it every time is not necessary. Thus, you can make local variables static. In this way, local variables will maintain values between the function calls.
There are many advantages of static storage class in C. Apart from this, you can use static modifier to global variables. Because of this, scope of variable stops at file. This is declared one. Hence, this is another use of static storage class in C.
To explain static storage class in C, you must know one more point. There is another use of static storage class on class data member. Because of this objects of class can share copy of member.
Example program

Explain register storage classes in C with examples

There are many advantages of register storage class in C. With register storage class, you can define local variables. You may store these variables in register class specifier than RAM. It means variable will have maximum size. Moreover, it is equal to register size. However, it cannot have unary & operator.
You must use register storage class specifier in C only for variables. Examples can be counters. As these variables require quick access. Finally, storage of variables depends on implementation and hardware restrictions.
Program example

Define extern storage class in C

You use extern storage classes in C in many ways. You can use them to refer global variable. Moreover, this variable is visible to all program files. A few points are necessary when you use extern storage class specifier in C. It is that variable will not initialise. But it will point variable name at storage location. This location is the place where definition of storage class was given.


Example program
So, you understood difference between static and extern storage classes in C. Even C multiple storage classes in declaration specifiers topic is clear. However, do not forget to practise C storage class and memory examples. In next chapter we will check Operators in C.



No comments:

Post a Comment