Рет қаралды 24,910
This video has a complete description of what scope, visibility and lifetime of a variable is. I have tried to explain all necessary things related to scope, visibility and lifetime of a variable.
*Scope - Area in the program where the variable is available.
*Visibility - Area in the program where the variable is accessible.
*Lifetime - Time period for which a variable is stored in some memory space(main memory or register).
Types of Scope:
1. Program Scope - Variable is available throughout the program.
2. File Scope - Variable is available throughout the file.
3. Block scope - Variable is available throughout the block in which it is declared.
4. Function Scope - Variable is available throughout the function in which it is declared.(usually for labels)
5. Prototype Scope - Variables passes as parameters to a function have this type of scope.
Visibility is a subset of Scope.
A variable may be available throughout the program, but it may not be accessible at some parts.
Types of lifetime:
1. Static lifetime - All static variables have static lifetime. They are stored in the memory till the program terminates.
2. Automatic Lifetime - All auto variables have automatic lifetime. They are stored in the memory till the block terminates.
3. Dynamic Lifetime - All variables which are created dynamically using malloc/new and deleted explicitly using free/delete have Dynamic Lifetime.
After having done with this video, I would recommend you all to watch my video on Storage Classes. Link to that video is given below.
• Storage Classes in C -...
Thanks.
Please visit my channel page if you liked this video and make sure you subscribe to get more videos on programming.
Link to my channel - / @shahidnihal