static variable Vs Global Variable
-
Hello Sir What is the main difference of static variable and Global Variable? My Suggestion is : Static variable accessing only through out the class and accessing need for scope resolution operator Global variable accessing through out the program and accessing the class object. Sir, My statements are correct or not
:~ Failure is Success If we learn from it!!:~
-
Hello Sir What is the main difference of static variable and Global Variable? My Suggestion is : Static variable accessing only through out the class and accessing need for scope resolution operator Global variable accessing through out the program and accessing the class object. Sir, My statements are correct or not
:~ Failure is Success If we learn from it!!:~
Scoping is possible with a static variable (I'm not talking about a data member of a class, but in general). You could put a static variable within a function and have it retain its value through the life of the program, but the scope is restricted - code from outside the function where it's declared cannot change it. A static global variable (global scope, but declared as static) is not visible outside the source file where it exists. You got it right about a static data member.
“Follow your bliss.” – Joseph Campbell
-
Hello Sir What is the main difference of static variable and Global Variable? My Suggestion is : Static variable accessing only through out the class and accessing need for scope resolution operator Global variable accessing through out the program and accessing the class object. Sir, My statements are correct or not
:~ Failure is Success If we learn from it!!:~
Just for the sake of completeness,
static
is only understood by the compiler to scope the entity. For the system, it is exactly the same as a global variable. So if you're using an assembler to write programs, you do not have the luxury ofstatic
and you have to do the scoping yourself.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)