Why should functions never be allowed to use global variables?
What will be an ideal response?
Unlike local variables, global variables are declared outside of any function in the program, and they remain in memory until the program ends. Also unlike a local variable, any statement in the program can use a global variable. Declaring a variable as global rather than local allows unintentional errors to occur when a function that should not have access to the variable inadvertently changes the variable's contents. Because of this, you should avoid using global variables in your programs. If more than one function needs access to the same variable, it is better to create a local variable in one of the functions and then pass that variable to the other functions that need it.
You might also like to view...
The ________ function calculates the periodic interest for a specified payment period on a loan or an investment
Fill in the blank(s) with correct word
A ________ in a PivotTable report is derived from formulas you create, which can include other PivotTable fields
A) row value B) summary statistic C) Value Field Setting D) calculated field