#include <iostream> #define N 10 void swap(int *a, int *b) //交换a,b { *a = *a ^ *b; *b = *a ^ *b; *a = *a ^ *b; } void reverse_arry(int a[], int arry_len) //将数组的头尾两端互换 { int i = 0, j = arry_len-1; while(i < j) { swap(&a[i], &a[j]); ++i; --j; } } int main() { int a[N]; for(int i = 0; i < N; ++i) { a[i] = i; } std::cout << "before: "; for(int i = 0; i < N; ++i) { std::cout << a[i] << " "; } std::cout << std::endl; reverse_arry(a, N); std::cout << "after reverse_arrt: "; for(int i = 0; i < N; ++i) { std::cout << a[i] << " "; } std::cout << std::endl; }
原文地址:http://blog.csdn.net/devil_pull/article/details/38419427