CBSE Class 12 Computer Science Question 65 of 103

Working with Functions — Question 12

Back to all questions
12
Question

Question 12

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

Answer

If we want to assign some value to the global variable without creating any local variable then global statement is used. It is not recommended because once a variable is declared global in a function, we cannot undo the statement. That is, after a global statement, the function will always refer to the global variable and local variable cannot be created of the same name. Also, by using global statement, programmers tend to lose control over variables and their scopes.