What is Storage class - Embedded C Programming Frequently Asked Interview Questions

What is Storage class? Explain with example

The storage class determines the part of memory where storage is allocated for an object (particularly variables and functions) and how long the storage allocation continues to exist. In C program, there are four storage classes: automatic, register, external and static.

They are declared at the start of a program’s block such as in the curly braces ( { } ). Memory is allocated automatically upon entry to a block and freed automatically upon exit from the block.
Automatic variables may be specified upon declaration to be of storage class auto. However, it is not required to use the keyword auto because by default, storage class within a block is auto. 

Automatic variables are allocated in the main memory of the processor; accessing these memory location for computation will take long time.When we required to optimize the execution time, move the critical variable to processor register. this can be done by using the register key word.when storage class is register, compiler is instructed to allocate a register for this variable.
scope of the register variable is same as auto variable. 

NOTE: Allocation of register is not guaranteed always, it depends on number register available in processor and number register used for manipulation. If you define 4 variable as register storage class and and processor has only 2 register for variable allocation, then compiler will allocate 2 variable in registers and treat the remaining 2 variable as auto variable. Therefore usage of register keyword should should be justified and cross checked with disassembly weather register is allocated or not. 

For using the external global variable from other files extern keyword is used.
any file can access this global variable and lifetime over entire program run. 

Static variable have lifetime over entire program run.Scope of this variable is limited based on the place of declaration.If static variable is defined in a file and not inside any function, then scope of the variable is limited within that file.If static variable is defined inside a function, then the scope of the variable is limited within that function.We can use this variable any file and any function indirectly by accessing through pointer.

More Embedded C Programming Questions And Suitable Answers:

Difference Between Process and Thread
What happens When Interrupt Occurs
Differences between Mutex And Semaphore
Unions-Why And When To Use
Embedded C Basic Questions
C Programming Questions for Job Interview
Embedded C Programming Basic Questions for Job Interview
Data Declarations And qualifiers
Variables and Pointers Volatile Or Costant
Dangling and Wild Pointers


Storage class in C 585022349243260203

Post a Comment

SPAMMING will not be Appreciated.


Hot in week



Our Channel

Contact Us


Email *

Message *

Follow by Email