+ 3
The static variable is changing..but it shouldn't change .can someone please explain me the reason as to why it is changing.
3 Answers
+ 5
Nikita Sharma static variable must change if updated with a new value because it is a class variable and only a single copy of it is created which is shared by all the objects of the class.
See if this helps.
https://www.sololearn.com/discuss/2139536/?ref=app
+ 4
Static variable will change they are not constant variable.
If static variable is declared as local it's scope is with in that function only.
If static variable is declared as global the scope of that variable is throughout the program.