devxlogo

Understanding Zero Initialization

Understanding Zero Initialization

To zero-initialize an object of type T means that the memory storage occupied by the object is set to binary zeros. More precisely, if T is a built-in data type, an enumeration type, or a pointer type, the storage is set to the value of 0 converted to T. For aggregates and class objects, zero-initialization means one of the following:

  • For a class type, the storage for each data member and each base-class subobject is zero-initialized.
  • For a union type, the storage for its first data member is zero-initialized.
  • For an array type, the storage for each element is zero-initialized.

However, if T is a reference type, no initialization is performed because there are no null references in C++.

devx-admin

Share the Post: