C Program To Reverse Array Elements (1-Dimensional Array)
Learn How To Reverse Array Elements in C Programming. It is important that we should know How A For Loop Works before getting further with the C Program Code. The following code is a C Program to Reverse an Array Without using another Array. We have manipulated the elements within a Single Array variable. There’s no need to take in another array for this purpose.
What is an Array?
An Array is basically a Data Structure to store data. Array is a set of consecutive memory elements used to store similar type of data items within it. Every Array has a Fixed Size which is declared at Compilation. However, you can make Arrays change its size Dynamically by using Dynamic Memory Allocation techniques with Pointers.
Also Read: C Program Code To Reverse a Number
Method 1: C Program To Reverse an Array of Integers without Function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include<stdio.h> int main() { int arr[20], limit, count; printf("Enter Limit:\t"); scanf("%d", &limit); printf("\nEnter %d Elements in 1-Dimensional Array\n", limit); for(count = 0; count < limit; count++) { scanf("%d", &arr[count]); } printf("\nArray Elements\n"); for(count = 0; count < limit; count++) { printf("%d\t", arr[count]); } printf("\nReverse of Array\n"); for(count = limit - 1; count >= 0; count--) { printf("%d\t", arr[count]); } printf("\n"); return 0; } |
Method 2: C Program To Reverse an Array using Function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include<stdio.h> void reverse(int a[], int n) { int i, j, temp; printf("Reverse of 1-D Array\n"); for(i = 0, j = n - 1; i <= n/2; i++, j--) { temp = a[i]; a[i] = a[j]; a[j] = temp; } for(i = 0; i < n; i++) { printf("%d\t", a[i]); } } void main() { int arr[20], count, limit; printf("\nEnter Limit of Array\n"); scanf("%d", &limit); printf("\nEnter Array Elements\n"); for(count = 0; count < limit; count++) { scanf("%d", &arr[count]); } reverse(arr, limit); printf("\n"); } |
Also Read: C Program To Reverse a String using Stack
Output

In case you get any Compilation Errors or have any doubts in this C Program To Reverse Array Elements with and without Functions, let us know about it in the Comment Section below.
I don’t want to do this, I want to do like this
// Before Reversing
a[0] = 10;
a[1] = 20;
a[2] = 30;
a[3] = 40;
a[4] = 50;
// After Reversing
a[0] = 50;
a[1] = 40;
a[2] = 30;
a[3] = 20;
a[4] = 10;
why i<=n/2