Program that print the elements of the array in reverse order by using a pointer.

Print the elements of the array in reverse order by using a pointer.

Program that 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();
}

Output:

Program that print the elements of the array in reverse order by using a pointer.

Hi, I am M.A Siddiqui. I'm a Computer Science Student, In this website, I'm teaching you Multiple languages and provides Projects and other Subjects Notes.

You may also like...

1 Response

  1. January 31, 2021

    […] Program that print the elements of the array in reverse order by using a pointer. […]

Leave a Reply

Your email address will not be published. Required fields are marked *