devxlogo

Take Advantage of the Automatic Initialization of Static Objects

Take Advantage of the Automatic Initialization of Static Objects

By default, all static variables, structs and arrays are automatically initialized to binary zeros before program’s outset. Likewise, static objects are initialized to binary zeros before their constructor is activated. Therefore, if you write a class whose objects always have static storage, you can take advantage of the automatic zero-initialization of its members and avoid explicit initialization within the constructor:

 class Message{private:  char msg[100];public:  Message() { for (int i =0; i

devx-admin

Share the Post: