diff --git a/src/Learning-C/Storage-Classes/introduction.md b/src/Learning-C/Storage-Classes/introduction.md index 7694f0f..4557373 100644 --- a/src/Learning-C/Storage-Classes/introduction.md +++ b/src/Learning-C/Storage-Classes/introduction.md @@ -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 | | -------- | -------- | ------------- | ------------------------ | ------------------- | diff --git a/src/README.md b/src/README.md index 041aa57..224e79a 100644 --- a/src/README.md +++ b/src/README.md @@ -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)