Computer Science, asked by dishdhauma, 10 months ago


When is global statement used ? why is its use not recommended?

Answers

Answered by Arman858
8

Global variables are dangerous because they can be simultaneously accessed from multiple sections of a program. This frequently results in bugs. Most bugs involving global variables arise from one function reading and acting on the value of a global variable before another function has the chance to set it to an appropriate value.

Global variables also make code difficult to read, because they force you to search through multiple functions or even modules just to understand all the different locations where the global variable is used and modified.

Similar questions