Thursday, July 9, 2009

What is the usefulness of declaring a global variable as static in C language?

by declaring a global variable as static you hide it from other files. Its declaration is only visible to the function defined in the same file. other file's functions cannot see this variable.

What is the usefulness of declaring a global variable as static in C language?
Exactly. Cheese is too expensive.
Reply:like a constant you mean? i think its useful when your program uses formulas. there is always a need for constant variables there. when its global, every program code block knows the variable (therefore no initialization and data type declaration needed everytime that variable is called). when its static, it doesn't change (like in pi = 3.1416...). hope this helps.
Reply:Ria I am sorry I cant go in to any details here but I will give you link for full reference:





C/C++ Programmer's Guide





http://publib.boulder.ibm.com/infocenter...
Reply:If you would like to use a global constant variable, then static global variable is useful.


No comments:

Post a Comment