c++ - Are global variables bad? -


In C / C ++, global variables are bad because my professor thinks they are?

The problem with global variables is that since each function reaches them, it becomes very difficult to find out which work actually read and write these variables Are there.

In order to understand how the application works, you have to take into account all the work that revises the global situation. This can be done, but as the application grows, it will be difficult due to virtually impossible (or at least the complete waste of time).

If you do not trust the global variable , Then you can cross the position between different functions according to the requirement. In this way you understand what each function does, because you do not have to take the global state into account.

Comments