int *pi = new int(0);
What's the significance of 0 here? Does it mean integer array of length 0?
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.
No it does not mean an array of size 0. it just means a value of 0 is assigned for the int value for which the pointer that is pi.
To me, the significance of 0 is also that somebody is saying,
I deliberately want this to be 0
rather than some 'default value' which [edit]in many cases is likely to also be 0
In many debug compiles will be set to 0, but in release compiles will often be the value already present in the uninitialized memory.