Editorial / Best Answer
Answered by:
Kranthi Kiran
We cannot use a 'static variable' declared in one file and use it in file 2.Reason: The purpose of 'static' keyword is to retain the value betwwen the function and to restrict thescope of the variable to the file.When a variable is declared as static it will be given memory in global area portion of the process segments with the variable mname prefixed with the file namefor Example: static int k; implies it is stored as "filename.k" in global segment.so if you try to use it in another file the compiler finds the variable prefix and flags out an error.
Can we use static variables in file2 if they are defined in file1 ? If yes, then how ?
Editorial / Best Answer
Answered by: Kranthi Kiran
We cannot use a 'static variable' declared in one file and use it in file 2.Reason: The purpose of 'static' keyword is to retain the value betwwen the function and to restrict thescope of the variable to the file.When a variable is declared as static it will be given memory in global area portion of the process segments with the variable mname prefixed with the file namefor Example: static int k; implies it is stored as "filename.k" in global segment.so if you try to use it in another file the compiler finds the variable prefix and flags out an error.
Related Answered Questions
Related Open Questions