Storage Classes
Storage Classes का Use, Variables / Function की Features को Describe करने के लिए किया जाता है। इन Features में मूल रूप से Scope, Visibility और Life-Time शामिल हैं जो किसी Program के Runtime के दौरान किसी Specific Variable के Existence का पता लगाने में हमारी Help करते हैं।
C Language 4 Storage Class का Use करता है।
1. Auto
यह किसी Function या Block के अंदर Declared सभी Variable के लिए Default Storage Class है। इसलिए, C Language में Program लिखते समय auto Keyword का Use शायद ही कभी किया जाता है। auto Storage Class variable को केवल उस Block/Function के भीतर ही Access किया जा सकता है जिसे उन्होंने Declare किया है और उनके बाहर नहीं (जो उनके Scope को Declare करता है)। इन्हें Basic Block/Function के भीतर Nested Blocks में Access किया जा सकता है जिसमें auto Variable Declare किया गया था। However, उन्हें उनके Scope से बाहर Access किया जा सकता है और साथ ही यहाँ दिए गए Pointers की Concept का Use करके बहुत Exact Memory Location की ओर Pointing किया जा सकता है जहाँ Variables Store रहते हैं। जब भी उन्हें Declare किया जाता है तो उन्हें By Default Garbage Value दिया जाता है।
2. Extern
Extern Storage Class Simply हमें बताते है कि Variable कहीं और Declare किया गया है, न कि Same Block के अंदर जहां इसका Use किया जाता है। Basically, Value अलग Block में Assign किया गया है और इसे एक अलग Block में भी Overwritten/Changed किया जा सकता है। तो एक Extern Variable कुछ भी नहीं है, लेकिन एक legal value के साथ Start किया गया एक Global Variable है जहां इसे कहीं और Use करने के लिए Declare किया जाता है। इसे किसी भी Function/Block में Access किया जा सकता है। साथ ही, किसी भी Function/Block में इसकी Declaration/Definition से पहले ‘extern’ Keyword रखकर एक सामान्य Global Variable को extern भी बनाया जा सकता है। यह मूल रूप से Signifies है कि एक New Variable Initialized नहीं कर रहे हैं I Instead केवल Global Variable का Used/Access कर रहे हैं। extern Variable का Use करने का Main Purpose यह है कि उन्हें दो अलग-अलग Files के बीच Accessed किया जा सकता है जो एक बड़े Program का Part हैं।
3. Static
static Storage Class का Use Static Variables को Declare करने के लिए किया जाता है जो C Language में Program Write करते समय Popularly Used किए जाते हैं। Static Variable में उनके Scope से बाहर होने के बाद भी उनके Values को Preserving करने की Property होती है! इसलिए, Static Variable अपने Scope में अपने Last Use के Value को Preserving करते हैं। So static class केवल एक बार initialized होते हैं और Program की Termination तक मौजूद रहते हैं। इस प्रकार, कोई New Memory Allocated नहीं की जाती है क्योंकि उन्हें फिर से Declared नहीं किया जाता है। उनका Scope उस Program के लिए Static है जिसके लिए उन्हें Declare किया गया था। Global static variables Program में कहीं भी Accessed जा सकता है। By Default से, उन्हें Compiler द्वारा 0 Value Assign किया जाता है।
4. Register
Register Storage Class Register Variable को Declare करता है जिनकी Functionality auto Variable के समान होती है। Deference इतना है कि Compiler इन Variables को Microprocessor के Register में Store करने की कोशिश करता है अगर एक Free Register Available है। यह Program के Runtime के दौरान Memory में Stored Variable की तुलना में Register Variable का Use बहुत Fast बनाता है। यदि एक Free Register Available नहीं है। Generally कुछ Variables जिन्हें किसी Program में Many Time Access किया जाना होता है, उन्हें register Keyword के साथ Declare किया जाता है जो Program के Run Time को बेहतर बनाता है। Pointers का Use करके Register Variable का Address Find नहीं कर सकते हैं।