int *pi = new int(0);
What's the significance of 0 here? Does it mean integer array of length 0?
It is an initializer (constructor parameter). The newly created int will have value of 0
.
It means you want a pointer to an int
, and for the value of that int
to be 0.
I once lost far too long on a bug that turned out to be someone wrote new char(10)
when they meant new char[10]
. Compiler was fine with it but it caused major corruption problems, which are so hard to spot. This was 10+ years ago and we didn't have the tools we do now. Will never forget it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With