0

Memory of static data memeber of a class

Class A { public: static int a; int b; }; int main() { A obj; cout << sizeof (A); cout << sizeof (obj); return 0; } Question is that output of above two sizeof is 4... Size of obj is as expected as one int is static and other is non static... Why size of class is also 4??? Where does and when memory of static variable is consumed as it is not associated with objects..

1st Jun 2018, 4:29 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Answers
+ 4
Static members of a class are still part of / can still be invoked using the instance of the class.
1st Jun 2018, 4:51 AM
Hatsy Rei
Hatsy Rei - avatar
0
But memory of those variable is not reflected either in class size or object size
1st Jun 2018, 12:43 PM
Ketan Lalcheta
Ketan Lalcheta - avatar