Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the use of making a global

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
What is the use of making a global variable "static" i.e.

static int x;

main ()
{
..
}
 
Hi,

If I remember correctly you make a global var static if you have a var with the same name in another file in the same project.
Below is taken from M$.'s mscxx.hlp.

When modifying a variable or function at file scope,
the static keyword specifies that the variable or function has internal linkage (its name is not visible from outside the file in which it is declared).

Hope that helps.

Pappy
 
When making a global variable static in a file you make sure that this variable is only visible from within the same file, and therefore it can't be accessed from any external file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top