Why should global variables be written to a minimum?

Asked 1 years ago, Updated 1 years ago, 148 views

The professor told me to use the discharge variable only when it's really inevitable Why is that?

If there are more functions, it's hard to transfer factors This is too much trouble

c c++ global-variable

2022-09-22 22:22

1 Answers

The problem with global variables is that all functions are accessible. It's easy to understand which function approaches this global variable when you're programming a small program If you develop a team or if the program gets bigger and bigger and has more functions, It's hard to manage the program because you don't know who's going to read or write this variable.

If you don't use global variables and pass factors as needed, This problem is reduced.


2022-09-22 22:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.