Reverse Array in C: Step-by-Step

Here is a method in C language to reverse the output of an array.

#include <stdio.h>

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    int size = sizeof(arr) / sizeof(arr[0]);
    
    printf("Original array: ");
    for (int i = 0; i < size; i++) {
        printf("%d ", arr[i]);
    }
    
    printf("\nReversed array: ");
    for (int i = size - 1; i >= 0; i--) {
        printf("%d ", arr[i]);
    }
    
    return 0;
}

The program first defines an integer array called arr, then calculates the size of the array. It then prints the contents of the original array through a loop, and reverses the output of the array through another loop. The final result is the reversed output.

bannerAds