Questions tagged [zero-initialization]

Please use this tag for asking questions related to initializing value of object to ints zero value type. For more details related to zero initialization please see https://en.cppreference.com/w/cpp/language/zero_initialization

  • For primitives zero-initialization creates them with a value-initialization of 0
  • For objects all of the primitives they are made up of are zero-initialized followed by default intialization
  • For arrays zero-initialization occurs using the rules above, based on whether the array elements are primitives or objects

For more information see: http://en.cppreference.com/w/cpp/language/zero_initialization

32 questions
-1
votes
1 answer

is there something wrong with my basic zero initialization code?

#include int main() { int x{ 19 }; std::cout << "Hola!" << '\n'; std::cout << "Me llamo Kay\n"; std::cout << "And I am " << x << " years old\n"; std::cout << "Who are you?\n"; int y{}; std::cin >> y; std::cout << "You are " << y << "?"…
-2
votes
1 answer

Zero initialization using the best and easy solution

Because of differences for zero initialization between compilers when using () {} I prefer memset. How safe is this code ? class A { public: int x; double y[55]; bool a, b; A() { memset(&x, 0, int(&b)+sizeof(bool)-int(&x));// cannot use…
Caty
  • 63
  • 6
1 2
3