C Language

Storage Class Question & Answer



Question : 1

What does static variable mean?



Answer :

Static variables are the variables which retain their values between the function calls. They are initialized only once their scope is within the function in which they are defined.



Question : 2

What are macros? What are its advantages and disadvantages?



Answer :

Macros are abbreviations for lengthy and frequently used statements. When a macro is called the entire code is substituted by a single line though the macro definition is of several lines.

The advantage of macro is that it reduces the time taken for control transfer as in case of function. The disadvantage of it is here the entire code is substituted so the program becomes lengthy if a macro is called several times.



Question : 3

What is static identifier?



Answer :

A file-scope variable that is declared static is visible only to functions within that file. A function-scope or block-scope variable that is declared as static is visible only within that scope. Furthermore, static variables only have a single instance. In the case of function- or block-scope variables, this means that the variable is not ―automatic‖ and thus retains its value across function invocations.



Question : 4

Where is the auto variables stored?



Answer :

Auto variables can be stored anywhere, so long as recursion works. Practically, they‘re stored on the stack. It is not necessary that always a stack exist. You could theoretically allocate function invocation records from the heap.



Question : 5

Where does global, static, and local, register variables, free memory and C Program instructions get stored?



Answer :

Global: Wherever the linker puts them. Typically the ―BSS segment‖ on many platforms.

Static: Again, wherever the linker puts them. Often, they‘re intermixed with the globals. The only difference between globals and statics is whether the linker will resolve the symbols across compilation units.

Local: Typically on the stack, unless the variable gets register allocated and never spills.

Register: Nowadays, these are equivalent to ―Local‖ variables. They live on the stack unless they get register-allocated.



Question : 6

Describe about storage allocation and scope of global, extern, static, local and register variables?



Answer :

Globals have application-scope. They‘re available in any compilation unit that includes an

appropriate declaration (usually brought from a header file). They‘re stored wherever the linker

puts them, usually a place called the ―BSS segment.‖

Extern? This is essentially ―global.‖

Static: Stored the same place as globals, typically, but only available to the compilation unit that

contains them. If they are block-scope global, only available within that block and its subblocks.

Local: Stored on the stack, typically. Only available in that block and its subblocks.

(Although pointers to locals can be passed to functions invoked from within a scope where that

local is valid.)

Register: See tirade above on ―local‖ vs. ―register.‖ The only difference is that

the C compiler will not let you take the address of something you‘ve declared as ―register.‖



Question : 7

What are register variables? What are the advantages of using register variables?



Answer :

If a variable is declared with a register storage class,it is known as register variable.The register variable is stored in the cpu register instead of main memory.Frequently used variables are declared as register variable as it‘s access time is faster.



Question : 8

What is the use of typedef?



Answer :

The typedef help in easier modification when the programs are ported to another machine. A descriptive new name given to the existing data type may be easier to understand the code.



Question : 9

What is storage class? What are the different storage classes in C?



Answer :

Storage class is an attribute that changes the behavior of a variable. It controls the lifetime, scope and linkage. The storage classes in c are auto, register, and extern, static, typedef.



CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad