|
I wrote a program like this
char * z = new char [6];
z = "abcde";
for (int k = 0; k <5; k ++)
{
cout << hex <<&z + k << endl;
cout << * (z + k) << endl;
}
delete [] z;
The previous operation is quite normal, and then delete [] z; there, it can not run, what is the reason? I guess it has something to do with that const, please help.
Then, in order to run this program, I wrote this:
char z [] = {'a', 'b', 'c', 'd', 'e'};
Ranch
for (int k = 0; k <5; k ++)
{
cout << hex <<&z + k << endl;
cout << * (z + k) << endl;
}
No need to delete, there is nothing wrong, but I suddenly found a strange phenomenon. This is its output:
0012FF24
a
0012FF29
b
0012FF2E
c
0012FF33
d
0012FF38
e
How can their memory locations differ by five? My original experiments were all four bits apart. Isn't a computer word four bytes long? Why is that? |
|