Skip to content

Commit

Permalink
update Storage Classes
Browse files Browse the repository at this point in the history
  • Loading branch information
nihalxkumar committed Mar 21, 2024
1 parent 23b07d1 commit e0f9760
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Learning-C/Storage-Classes/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Storage classes define 4 properties of a variable in C:
1. Storage class: The storage class of a variable determines where the variable is stored in memory. stored in RAM or CPU registers. There are 4 storage classes in C:
- **auto**: Variables with the `auto` storage class are stored on the stack.
- **register**: Variables with the `register` storage class are stored in the CPU registers. Registers are faster and limited in number, so the compiler may ignore the `register` keyword.
- **static**: Variables with the `static` storage class are stored in the data segment. Defined only once and retains its value between function calls; memory is not deallocated when the function exits.
- **extern**: Variables with the `extern` storage class are used to declare variables that are defined in another part of the program. The extern keyword does not allocate memory for the variable but rather informs the compiler about the existence of a variable defined elsewhere. When a local variable shares the same name as a global variable, the local variable takes precedence within its scope. To access the global variable in such a scenario, you can use the scope resolution operator ::.
- **static**: Variables with the `static` storage class are stored in the data segment. Defined only once and retains its value between function calls; memory is not deallocated when the function exits. Default value is 0. static variables can be accessed only in the declared file.
- **extern**: Variables with the `extern` storage class are used to declare variables that are defined in another part of the program. The extern keyword does not allocate memory for the variable but rather informs the compiler about the existence of a variable defined elsewhere. When a local variable shares the same name as a global variable, the local variable takes precedence within its scope. To access the global variable in such a scenario, you can use the scope resolution operator :: If global variable is initialized then memory will be allocated for it.

| | Storage | Default Value | Scope | Lifetime |
| -------- | -------- | ------------- | ------------------------ | ------------------- |
Expand Down
1 change: 1 addition & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This is to document my progress and to share my learnings with others who may fi
- [Strings](./Learning-C/Strings.md)
- [Functions](./Learning-C/Functions/Functions.md)
- [Recursion](./Learning-C/Recursion/introduction.md)
- [Storage Classes](./Learning-C/Storage-Classes/introduction.md)
- [Acknowledgements](./Learning-C/Acknowledgements.md)

</details>
Expand Down

0 comments on commit e0f9760

Please sign in to comment.