+ 3

The static variable is changing..but it shouldn't change .can someone please explain me the reason as to why it is changing.

https://code.sololearn.com/c3fPEx7hZ9Cy/?ref=app

20th Jan 2020, 2:22 PM
Nikita Sharma
Nikita Sharma - avatar
3 Respostas
+ 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
20th Jan 2020, 2:27 PM
Avinesh
Avinesh - avatar
+ 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.
20th Jan 2020, 4:52 PM
Bhargava Ram
Bhargava Ram - avatar