0
Why we should never declare global variables
3 Respostas
+ 11
'Never' is an exaggeration, although global variables do have their cons. One of the most direct reasons is because a global variable is subjected to change everywhere - Functions, class methods, main(). This makes it hard to trace, and your program equally hard to debug when errors occur.
+ 4
Depends on need.
If you need a global variable, go for it.
Usually, the story begins from main() and ends in main(), that's why people use local variable.
+ 4
Global variables are typically used in game programming because they are much faster to read/modify.