|
These two are still different
int * p = new char (97); // The string at p: "a" starts with a, followed by some spaces, it is estimated to end at\0
int n = strlen (p); // n = 16 the length of the string is variable
int * p = new char [97]; // pThe output string is: "Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun Tun "Tuntun Tuntun Tuntun Tuntun Tuntun Tuntun Tuntun Tuntun"
int n = strlen (p); // n = 112 The value is uncertain, it is estimated that it will end when it encounters\0 in memory.
I'm confused about these two ways of writing! Which one should I use, and how much memory are allocated to them in these two ways? |
|