STORAGE CLASS

Thursday, January 13, 2011 ·

Storage Class

  
Every variable and function in C has two attributes: type and storage-
class. There are 4 kinds of storage-class: automatic, external, register and static. Keyword-its own: auto, extern, register, static.
Keyword auto is used to explicitly declare the storage-class automatic.
example:
auto int a, b
auto float f;



Variables declared within a block is automatic, the implicit. So the auto keyword is rarely used. Meaning of auto storage-class If a block to have entered, the memory allocated for variables automatic. These variables are local in the block. At that time block left (exit block), the memory allocated for the variable- auto variables that become free again. So the value of this auto variables be lost. If the block is entered again later, the system allocates more memory for auto variables, but the previous value is not known.
So the lifetime of an auto variable block adalh since it entered to date blocknya abandoned.

Strorage-class extern

  • One way to distribute information across blocks and across functions is to use an external variable. 
  • Variables declared outside the function gets memory allocation 
  • permanent (as long as the active program). Storage-classnya extern.

0 comments:

Archives