If I am not mistaken if I were to declare a global char array, its elements would be initialized to \0’s. The same if I were to declare a static global or a static local. But what about a static field?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes. In C++ terminology, a field is called a “data member”.
Paragraph 9.4.2.7 of the C++03 standard states “Static data members are initialized and destroyed exactly like non-local objects.”.
Section 3.7.1 “Static storage duration” states “All objects which neither have dynamic storage duration nor are local have static storage duration.”
Section 3.6.2 “Initialization of non-local objects” states “Objects with static storage duration shall be zero-initialized before any other initialization takes place.”
So, if you don’t explicitly initialize your data member to something else, it keeps its zero-initialized value.