Reversing an array In place

后端 未结 11 918
温柔的废话
温柔的废话 2020-12-21 04:20

Okay so I\'ve tried to print and Array and then reverse is using another array But I\'m trying to create a For Loop that will take an array and reverse all of the elements i

11条回答
  •  悲哀的现实
    2020-12-21 05:23

    Just my 2 cents...

    #include 
    #include 
    
    int main() {
          int arry[] = {0, 1, 2, 3, 4, 5};
          int* s = arry;
          int* e = arry + (sizeof(arry) / sizeof(arry[0])) - 1;
          while (s < e) {
            *e ^= *s;
            *s ^= *e;
            *e ^= *s;
            s++;
            e--;
          }
          for (size_t i = 0; i < (sizeof(arry) / sizeof(arry[0])); i++) {
            fprintf(stderr, "%d, ", arry[i]);
          }
          fprintf(stderr, "\n");
       }
    

提交回复
热议问题