C Program to Reverse Array Elements using Pointer

C Program to Reverse Array Elements using Pointer:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>

main()
{
   int size,i,arr[50];
   int *ptr;

   ptr=&arr[0];

   printf("Enter the size of array : ");
   scanf("%d",&size);

   printf("\nEnter %d integers into array: ",size);
   for(i=0;i<size;i++)
    {
      scanf("%d",ptr);
      ptr++;
    }

   ptr=&arr[size-1];

   printf("\nElements of array in reverse order are :");

   for(i=size-1;i>=0;i--)
    {
      printf("%d\t",*ptr);
      ptr--;
    }
}

OUTPUT:

Enter the size of array : 5

Enter 5 integers into array: 1 7 6 2 8

Elements of array in reverse order are :8       2       6       7       1

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.