HI,
Could anyone please tell me what are static variables and what exactly
are there features.
I am a little bit confused.
There are static member variables, local static variables inside a
function definition, and global static variables at file scope.
In a nutshell, storage for static member variables is allocated
independently of any object of the class of which they are a member.
They must be initialized outside of the class definition (i.e. at
global scope).
Inside the body of a function definition, storage for a static
variable is allocated before the program runs. The value of such a
variable remains persistent beyond the scope of the function being
called. The initialization of such function static variables is done
before the function is called the first time -- sometimes well before,
but sometimes only at the last moment. I believe this is
implementation defined (please someone correct me if I'm mistaken,
don't have time right now to look it up...).
Variables declared globally outside a class or function body with the
keyword "static" are only visible at file scope in the translation
unit in which they are defined. IOW, you can have multiple variables
with the same name if they are all declared with the keyword "static"
and there is only one per translation unit.