STORAGE CLASSES IN C

Hello everyone, This is my first post to dev.to in which I wanna tell you about STORAGE CLASSES IN C..

Storage classes in C are a set of keywords that guide the compiler in storing and manipulating variables in memory.
A Storage Class define…


This content originally appeared on DEV Community and was authored by Anuj Raghuwanshi

Hello everyone, This is my first post to dev.to in which I wanna tell you about STORAGE CLASSES IN C..

Storage classes in C are a set of keywords that guide the compiler in storing and manipulating variables in memory.
A Storage Class defines following attributes about a variable in C.
1.Scope :- Where will this variable be available.
2.Default initial value :- what will be the initial value
3.LifeTime :- Life of that variable in a program

There are FOUR Storage Classes in C which are most often used:
1.Automatic
2.External
3.Static
4.Register

Automatic Storage Class

A variable defined without any Storage Class specification is by default an automatic variable.

int variable_name and auto int variable_name are same.

Scope :- Local to the function body they are defined in
Default Value :- Garbage value
LifeTime :- Till the end of the function block they are defined in.

External Storage Class

They are same as global variable. External storage class in C, represented by the keyword 'extern', is used to give a reference of a global variable that is visible to all program files. When a variable is declared with the 'extern' keyword, it indicates that the variable is defined in another file and the current file is using its reference.
Extern variables cannot be initialised. They only point to an existing variable.
extern int variable_name

Scope :- Global to the program they are defined in
Default Value :- zero
LifeTime :- They are available throughout the lifetime of the program

Static Storage Class

Static storage class in C, represented by the keyword 'static'.
static int variable_name
static variable retains its value between function calls.Static variables are initialised only once.

Scope :- Local to the block they are defined in
Default Value :- zero
LifeTime :- throughout the program

Register Storage Class

Register variable requests the compiler to store the variable in the CPU register instead of storing it in the memory to have faster access.
register int variable_name

Scope :- Local to the function they are defined in
Default Value :- Garbage Value
LifeTime :- Available till the end of the function block in which the variable is defined.


This content originally appeared on DEV Community and was authored by Anuj Raghuwanshi


Print Share Comment Cite Upload Translate Updates
APA

Anuj Raghuwanshi | Sciencx (2024-08-29T20:09:15+00:00) STORAGE CLASSES IN C. Retrieved from https://www.scien.cx/2024/08/29/storage-classes-in-c/

MLA
" » STORAGE CLASSES IN C." Anuj Raghuwanshi | Sciencx - Thursday August 29, 2024, https://www.scien.cx/2024/08/29/storage-classes-in-c/
HARVARD
Anuj Raghuwanshi | Sciencx Thursday August 29, 2024 » STORAGE CLASSES IN C., viewed ,<https://www.scien.cx/2024/08/29/storage-classes-in-c/>
VANCOUVER
Anuj Raghuwanshi | Sciencx - » STORAGE CLASSES IN C. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/29/storage-classes-in-c/
CHICAGO
" » STORAGE CLASSES IN C." Anuj Raghuwanshi | Sciencx - Accessed . https://www.scien.cx/2024/08/29/storage-classes-in-c/
IEEE
" » STORAGE CLASSES IN C." Anuj Raghuwanshi | Sciencx [Online]. Available: https://www.scien.cx/2024/08/29/storage-classes-in-c/. [Accessed: ]
rf:citation
» STORAGE CLASSES IN C | Anuj Raghuwanshi | Sciencx | https://www.scien.cx/2024/08/29/storage-classes-in-c/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.