我正在用 C++ 复制一个数组,代码如下:
int arr1[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int *source = arr1;
size_t sz = sizeof(arr1) / sizeof(*arr1); // number of elements
int *dest = new int[sz]; // uninitialized elements
while (source != arr1 + sz)
*dest++ = *source++; // copy element and increment pointers
int *p = dest;
while (p != dest + sz) {
cout << *p++ << endl;
}
运行上述代码后,我得到:
714124054
51734
9647968
9639960
0
0
0
0
0
0
有什么问题?