In a small code, we can track values of global variables. But if the code size grows, they make code less understandable (hence less maintainable). It becomes difficult to track which function modified the value and how.
- In above code, we notice one of the biggest problem of global variable that is Debugging. It means if we trying to figure out where that variable c has changed between thousands of lines of code is very difficult job.
- In multihreaded environment a global variable may change more than once (in different execution orders) and cause more problems.
- Global variables are generally used for constants. Using them for non-const values is not recommended.
- Initialization of global and static variables in C
- Redeclaration of global variable in C
- How Linkers Resolve Global Symbols Defined at Multiple Places?
- Why overriding both the global new operator and the class-specific operator is not ambiguous?
- Variables in C++
- Can we access global variable if there is a local variable with same name?
- Variables and Keywords in C
- Scope of Variables in C++
- Static Variables in C
- Constants vs Variables in C language
- Operations on struct variables in C
- Initialization of static variables in C
- Templates and Static variables in C++
- Implicit initialization of variables with 0 or 1 in C
- C++ 17 | New ways to Assign values to Variables
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.