Tutorial 14


Scope of the variables in C++ provides the accessibility of the variable. We have local, global, actual and formal variables. Variables inside any function are local variables, they are accessible to that function only. Variables declared outside any function main also globally are called global variable, these variables can be accessed by functions globally. Variable during function call are called actual variable however, the variables that receives actual variables are called formal variables. We have four types of storage types for the variables in C++ namely auto, extern, register and static. This refers to the life of the variable during the program execution, i.e. the birth and death of the variable, the creation and destruction of the variable. By default all the variables are of auto type, they exist till the time the block/function in which they have been created/declared is active and dies as soon as the block/function is exit.