+ 1
Why it's is essential variable(b) to be static?
class A { static int b;//without static error public: void show() { cout <<b; } }; int A :: b; int main() { A x; x.show(); } (output 0)//how it's 0
4 Answers
+ 5
Coder18
It being essential depends on what the code needs to accomplish.
The static value remains the same for each instance of the class, it is defined inside of.
+ 2
Coder18
edit: in your example you did not give b a value making it 0.
https://code.sololearn.com/cB4rCf31BS9l/?ref=app
+ 1
#Manual if not write static in this code,there is an error,why?
0
and this code output 0,so b=0;but there isn't adjudged 0 to b anywhere :(