Friday, August 29, 2014

static strucutres


Static rule for user defined data type(struct, union)
  • The static modifier for the struct limits the scope of visibility of the structure to the current translation unit (i.e. the file).
  • even structure also the data type like integer. but the differnet between the int and struct is , int is  predefined data type and struct is the user defined data type.
  • so the following rules will be applicable to the struct and any user define data type ( union)
    • when applied to a variable declared inside a function, the value of that variable will be preserved between function calls.
    • when applied to a variable declared outside a function, or to a function, the visibility of that variable or function is limited to the "translation unit" it's declared in - ie the file itself. 
    • For variables this boils down to a kind of "locally visible global variable".

Reference:

No comments:

Post a Comment