Storage classes in c define scope, life time, Storage location and default value of a variable.
General confusion what's term scope and life time in c-language. Let's start with a situation.
Situation1 : A person is sent to jail for any allege activity for 1 year. During this time he can't go outside the jail. So person has area limitation and time limitation.
Any one get my idea from above example.
- Scope means area limitation
- Life time means time limitation
Same thing also apply with c language's program. Where scope define area or block ({}) in which variable define and life time is how long time that variable is available for execution.
// first block or scope
{---------(1)
//if we define any variable inside it it is bounded by first block so scope of variable is inside ({}) and life time is total time taken by machine to execute this block.
}----(outside)
Situation2 : Person is sent to jail but which jail(India, US, UK or any other location) . means where jail is situated. This term in programming define by Storage location for variable.
Conclusion : Storage location define where variable will be stored ex. ram, CPU register or other.
Situation3 : Person is has no record for any allege activity before this then police register new record for that person. means if we didn't define value for any declared variable then compiler automatically assign new value to this.
Default value for variable means when we declare it and didn't initialize then compiler gives a default value.
No comments:
Post a Comment