Home / Programs / C Program to Read integers into an array and Reversing them using Pointers
🚀 Programming Example

C Program to Read integers into an array and Reversing them using Pointers

👁 1,780 Views
💻 Practical Program
📘 Step Learning
C Program to Read integers into an array and Reversing them using Pointers

💻 Program Code

#include<stdio.h>
#include<conio.h>
#define MAX 30

void main() {
   int size, i, arr[MAX];
   int *ptr;
   clrscr();

   ptr = &arr[0];

   printf("\nEnter 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("\nElement%d is %d : ", i, *ptr);
      ptr--;
   }

   getch();
}
                        

🖥 Program Output

Enter the size of array : 5
Enter 5 integers into array : 11 22 33 44 55
Elements of array in reverse order are :
Element 4 is : 55
Element 4 is : 44
Element 4 is : 33
Element 4 is : 22
Element 4 is : 11
                            

📘 Explanation

none
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.