fork download
  1. #include <iostream>
  2. #include <memory>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. #define SIZE (10)
  8. #define arraylen(b) (sizeof(b)/sizeof(*b))
  9.  
  10. void printArray(int array[], int offset, int len);
  11. void reverseArray(int array[], int offset, int len);
  12.  
  13. int main() {
  14.  
  15. int array[SIZE];
  16. int len = arraylen(array);
  17.  
  18. for (int i = 0; i < len; i++)
  19. array[i] = i;
  20.  
  21. printArray(array, 0, len);
  22. reverseArray(array, 0, len);
  23. printArray(array, 0, len);
  24.  
  25. return 0;
  26. }
  27.  
  28.  
  29. void printArray(int array[], int offset, int len) {
  30. for (int i = 0; i < len; i++)
  31. cout << array[i + offset] << ' ';
  32. cout << endl;
  33. }
  34.  
  35. void reverseArray(int array[], int offset, int len) {
  36. int *temp = new int[len];
  37. memmove(temp, &array[offset], len * sizeof(int));
  38. for (int i = 0; i < len; i++)
  39. array[i + offset] = temp[len - i - 1];
  40. delete [] temp;
  41. }
  42.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
0 1 2 3 4 5 6 7 8 9 
9 8 7 6 5 4 3 2 1 0