A Little about the blog.....

This blog contains all the interview questions that i face during my interviews with various MNC's. I am trying to post the solutions for almost all the questions and i have covered few important topics which would be frequent topics in interviews. I hope the blog would be useful not only for the job aspirants but also to the one who tries to upgrade his/her knowledge in C and Embedded concepts......

please enter your mail address in the above mail address box to get the immediate updates of the new interview questions.....

Wednesday, November 9, 2011

Things to Remember : Storage classes in C

* SCOPE OF A VARIABLE: A variable defined in a block can be accessed in that block and all its internal blocks only (In default,a variable defined in block cannot be accessed by any other external blocks). It is called as the scope of a variable.

* To make the variable valid and accessible through out our operations, we define the variable with different storage classes as required per our needs.

* In default storage class (AUTO), the variable defined is valid as long as the control is in the block where it is defined. when the control comes out of the loop, the variable dies and the memory allocated is unreserved.

* For STATIC & GLOBAL variables, the memory is allocated as soon as the program gets loaded into the memory (before the execution of main() function) and hence these variables are also called as LOAD TIME VARIABLES. The memory for these variable gets de-allocated just before the termination of the program from the memory.

LIFETIME of a VARIABLE: The period for which after a variable is defined and allocated with memory and the memory allocated is deallocated is called the lifetime of the variable.

Note: The lifetime of a declared element is the period of time during which it is available for use. Variables are the only elements that have lifetime; for this purpose, the compiler treats procedure arguments and function returns as special cases of variables. The lifetime of a variable represents the period of time during which it can hold a value. Its value can change over its lifetime, but it always holds some value.

No comments:

Post a Comment