Write C++ program to print the elements of the array in reverse order using a pointer


I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int arr[5],i;
  7. int *p=arr;
  8. cout<<"Enter five numbers separated by space:";
  9. cin>>*p>>*(p+1)>>*(p+2)>>*(p+3)>>*(p+4);
  10. cout<<"Your entered numbers in reverse order are:\n";
  11. for(i=4;i>=0;i--)
  12. cout<<*(p+i)<<endl;
  13.  
  14.  
  15. return 0;
  16.  
  17. }
  18.  

Result

C++ language techstudy.org

     





Related Topics




Popular Posts