Print the elements of the array in reverse order by using a pointer.
Object: Write a Program that print the elements of the array in reverse order by using a pointer. C++ projects for beginners with source code
Code:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int num[5],i;
int *pi[5];
cout<<“Enter Fives Numbers:\n”;
for(i=0;i<5;i++)
{
cin>>num[i];
pi[i]=&num[i];
}
cout<<“Original Order:\n”;
for(i=0;i<5;i++)
{
cout<<*pi[i]<<” “;
}
cout<<“\nReverse Order:\n”;
for(i=4;i>=0;i–)
{
cout<<*pi[i]<<” “;
}
getch();
}
#include<iostream> #include<conio.h> using namespace std; void main() { int num[5],i; int *pi[5]; cout<<"Enter Fives Numbers:\n"; for(i=0;i<5;i++) { cin>>num[i]; pi[i]=&num[i]; } cout<<"Original Order:\n"; for(i=0;i<5;i++) { cout<<*pi[i]<<" "; } cout<<"\nReverse Order:\n"; for(i=4;i>=0;i--) { cout<<*pi[i]<<" "; } getch(); }
Pingback: Top 40 projects with C++ for beginners in 2021