AshfaqFardin

Reverse array using pointer indexing

Jul 31st, 2021
1,059
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void printArray(int *pointer, int size){
  6.     for(int i = 0; i < size; i++){
  7.         cout << pointer[i] << " ";
  8.     }
  9. }
  10. void reverseArray(int *pointer, int size){
  11.     for(int i = size-1; i >= 0; i--){
  12.         cout << pointer[i] << " ";
  13.     }
  14. }
  15.  
  16. int main()
  17. {
  18.     int size = 5;
  19.     int arr[] = {1, 2, 3, 4, 5};
  20.    
  21.     cout << "Original Form: ";
  22.     printArray(arr, size);
  23.    
  24.     cout << endl;
  25.     cout << "Reversed Form: ";
  26.     reverseArray(arr, size);
  27.    
  28.     return 0;
  29. }
  30.  
RAW Paste Data