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

3rd Jun 2018, 10:51 AM
Aman Kumar Jain
Aman Kumar Jain - avatar
5 Respostas
+ 2
STATIC variables are automatically initialized to 0.
3rd Jun 2018, 11:08 AM
Disvolviĝo;
Disvolviĝo; - avatar
+ 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.
3rd Jun 2018, 10:57 AM
Disvolviĝo;
Disvolviĝo; - avatar
+ 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.
3rd Jun 2018, 11:15 AM
Disvolviĝo;
Disvolviĝo; - avatar
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..
3rd Jun 2018, 11:06 AM
Aman Kumar Jain
Aman Kumar Jain - avatar
0
what does that line does?
3rd Jun 2018, 11:10 AM
Aman Kumar Jain
Aman Kumar Jain - avatar