50. Reverse an Array Using Only Pointers

Back To All Submissions
Previous Submission
Next Submission

Code

#include <stdio.h>

void reverse_array(int *ptr, int n) {
    // Your logic here
    int* address = ptr; 
    for ( int j = n -1 ; j >= 0; j--){
        address = ptr +j;
        printf("%d ", *(address));
    }
}

int main() {
    int n;
    scanf("%d", &n);

    int arr[100];
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }

    reverse_array(arr, n);

    // for (int i = 0; i < n; i++) {
    //     printf("%d", arr[i]);
    //     if(i < n-1){
    //         printf(" ");
    //     }
    // } // what is thisssssss????

    return 0;
}

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote