98.0k views
1 vote
Which of the following best describes the required modification to eliminate global variables?

a. Remove all local variables and replace them with global constants.
b. Replace global variables with local constants.
c. Add arguments, parameters, and return values to eliminate global variables.
d. Keep using global variables for better code readability.
e. Use global constants instead of local variables for simplicity.

1 Answer

5 votes

Final answer:

The required modification to eliminate global variables is to add arguments, parameters, and return values.

Step-by-step explanation:

The required modification to eliminate global variables is to add arguments, parameters, and return values. This means that instead of relying on global variables, functions should take in the necessary data as arguments, process it using local variables, and then return the result as a return value. This helps to encapsulate data and avoid the use of global variables which can lead to unintended modifications and difficulties in debugging and maintaining the code. The best approach to eliminate global variables is to use local variables within functions or methods and pass data between them using arguments, parameters, and return values. This promotes encapsulation, modularization, and reduces the reliance on global state, which can lead to better code organization and maintainability.

User AbdelAli
by
7.5k points