Final answer:
Using keyword 'static' on a global variable limits its scope to the file, making it inaccessible from other files. For a local variable, it changes the storage duration, allowing the variable to maintain its value across function calls.
Step-by-step explanation:
In programming, the use of the keyword static can alter the behavior of both global and local variables in several important ways:
- For a global variable, using static limits the scope of the variable to the file in which it is declared. This means that even though the variable is global within the file, it is not accessible from other files that are part of the same program. By default, global variables have external linkage, which means they can be accessed from other files, but declaring them as static gives them internal linkage, and they become inaccessible outside their defining file.
- For a local variable, applying the static keyword changes its storage duration from automatic to static. Normally, a local variable's lifetime is limited to the execution of the block in which it is defined; however, a static local variable maintains its state between function calls. Its value persists for the lifetime of the program, allowing the variable to retain information between calls to the function without being reinitialized each time.