Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void reverse_1d_array(int* arr_begin, int* arr_end)
- {
- if (arr_begin != nullptr && arr_end != nullptr)
- {
- int* firstPointer = arr_begin;
- int* secondPointer = arr_end;
- int arrSize = arr_end - arr_begin + 1;
- for (int i = 0; i < arrSize / 2; i++)
- {
- int* temp = firstPointer;
- firstPointer = secondPointer;
- secondPointer = temp;
- firstPointer--;
- secondPointer++;
- }
- }
- }
- int main()
- {
- int arr[] = { 1, 3, 5, 7 };
- int arrSize = sizeof(arr) / sizeof(arr[0]);
- reverse_1d_array(&arr[0], &arr[arrSize - 1]);
- cout << arr[0] << " " << arr[1] << " " << arr[2] << " " << arr[3];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement