指针逆序数组

来源:互联网 发布:曼秀雷敦润肤乳 知乎 编辑:程序博客网 时间:2024/06/15 23:34
#include<iostream>using namespace std;void invert(int* x, int n){int* p, temp, *i, *j, m = (n - 1) / 2;i = x;j = x + n - 1;p = x + m;for (; i <= p; i++, j--){temp = *i;*i = *j;*j = temp;}}int main(){int i, a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };for (int i = 0; i < 10; i++)cout << a[i] << endl;invert(a, 10);for (int i = 0; i < 10; i++)cout << a[i] << endl;system("pause");return 0;}

0 0
原创粉丝点击