The static variable is changing..but it shouldn't change .can someone please explain me the reason as to why it is changing. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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
2 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
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