0
Can anyone please explain me this Code!!
#include <iostream> using namespace std; class A{ static int b;int c=0; public: void show() { cout<<++b<<++c; } }; int A::b; int main() { A x,y; x.show(); y.show(); return 0; } //Output 1121
5 Respostas
+ 2
STATIC variables are automatically initialized to 0.
+ 1
The static variable "b" is shared among the objects of the class A. But the "c" isn't.
So if you change the "b", it is reflected in other onjects.
+ 1
"static int b;"?
This is a declaration. The instance is
"int A::b;". So if there isn't the instance, link error will happen.
0
hey Programanta ludanto
we didnt initialise b=0 even it is printing the value as if it is initialised to 0.
and what does int A::b; states? i didnt understood this line..
0
what does that line does?