//编写程序,使用指针实现逆序打印一维整型数组所有元素的操作。
//数组a: 1 3 7 2 9 6 5 8 2 0 4 8 2 0 4
#include <iostream>
using namespace std;
int main()
{
int array[15] = { 1,3,7,2,9,6,5,8,2,0,4,8,2,0,4};
int* ptr_array;
ptr_array = array;
int* ptr_start = array;
int* ptr_end = array + 15;
int temp;
while (ptr_start <= ptr_end)
{
temp = *ptr_end;
*ptr_end = *ptr_start;
*ptr_start = temp;
ptr_start++;
ptr_end--;
}
越界了。
int* ptr_end = array + 14;
另外,不要硬编码14,而要用array数组的长度来计算出这个14。