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...
Which of the following is not a type of repetition statement in Java?
a. while statement. b. do…while statement. c. for statement. d. loop statement.
Another pessimistic designer asks why we go to the trouble of defining a strategy with an official-sounding name like first-fit. This designer claims that a first-fit strategy is equivalent to nothing more than random memory placement.Do you agree? Explain.
What will be an ideal response?
Which HTML tag is used to define an external style sheet?
A.