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

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

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


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.