数组逆序

#include <iostream>
using namespace std;

int main()
{
   char buf[] = {1, 3, 4, 2, 6, 5}; 

   int start = 0;
   int end = sizeof(buf) - 1;

   while(start < end)
   {   
      int temp = buf[start];
      buf[start] = buf[end];
      buf[end] = temp;

      start++;
      end--;
   }   

   for(int i = 0; i < sizeof(buf); i++)
   {   
      cout << (int)buf[i] << ' ';
   }

   cout << endl;

   return 0;
}
$ ./a.out    
5 6 2 4 3 1 
posted @ 2022-05-19 17:15  thomas_blog  阅读(29)  评论(0编辑  收藏  举报