Why should a variable not be declared as a module variable?

  1. It prevents a procedure from being self contained.

  2. It makes it easier to document the code.

  3. Local variable names can be reused in other procedures.

  4. Both a and b.

  5. All of the above.


Correct Option: E

AI Explanation

To answer this question, you need to understand the concept of variable scope and the implications of declaring a variable as a module variable.

Option A) It prevents a procedure from being self-contained - This option is correct. When a variable is declared as a module variable, it can be accessed and modified by any procedure within the module. This means that the variable's value can be changed by multiple procedures, making it difficult to determine which procedure is responsible for modifying it. This breaks the principle of encapsulation and can make the code less modular and harder to understand and maintain.

Option B) It makes it easier to document the code - This option is incorrect. Declaring a variable as a module variable does not directly affect the ease of documenting the code. Documentation is important for understanding the purpose and behavior of the code, but it is not directly related to the scope of variables.

Option C) Local variable names can be reused in other procedures - This option is correct. When a variable is declared as a local variable within a procedure, it is only accessible within that procedure. This means that the same variable name can be used in different procedures without causing conflicts. This can make the code more readable and reduce the chances of unintended side effects.

Option D) Both a and b - This option is incorrect. Option B is incorrect, as explained above.

Option E) All of the above - This option is correct. Both options A and C are correct, as explained above.

Therefore, the correct answer is E) All of the above. This option is correct because it includes both options A and C, which accurately describe the reasons why a variable should not be declared as a module variable.

Find more quizzes: