What is the difference between global int & static int declaration

Showing Answers 1 - 3 of 3 Answers

RaviPrakash

  • Mar 30th, 2007
 

Static int variable are accessed only inside the file where it is defined. Thus we can have same variable name  in 2 files if the variable is defined as static. The scope of the variable is limited to the file in which it is defined.

On the other hanad if the variable is not defined as static and defined globally then it can be accessed across the files. To access the variable which is global variable and decleared and defined in file A, keyword "extern" is used in front of the variable in file B. This indicated to compiler while compiling that the variable is defined in some other file other than B and continues compiling and while linking the variable it search for the actual defination and links.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions