Skip to main content

Posts

Showing posts with the label static data

Static members

Those of you who are familiar with C, have used static keyword to mean opposite of automatic. A static variable has a lifetime of complete program execution. That is to say it does not get destroyed when you leave the block where it is defined. What is static in C++? Static storage Automatic variables are destroyed when a function or block in which it is defined exits  where as static variables have static duration . That is they remain alive till the end of program.  And static global variables and functions have internal linkage . That is they are visible only in the file they are defined in.  A non-static global variable or function has external linkage. It is visible in the entire program. Let us discuss about static members of a class. Static member of a class does not belong to an object, but belongs to the class. Static data member Ordinary data members are present in each object and they are different for each object. But a  static data ...