Given two classes with different constructors:
#include <iostream>
struct A {
int x;
A() {};
};
struct B {
int x;
B() = default;
};
int main() {
int x = 5;
x = 7;
printf("before: %d\n", x);
new(&x) A();
printf("%d\n", x);
new(&x) B();
printf("%d\n", x);
}
Output is:
before: 7
7
0
Why default ctor zero-initializes int x?