'recursive function for checking if the array is sorted not working

i wrote this isSorted function that will check if the array is sorted or not if the array is sorted, it will return 0, else it will return 1, but for some reason, the function keeps on returning 0 even if the array is not sorted. This is the full program with the function

struct array {

    int A[10];
    int size;
    int length;
};


void displayArray(struct array arr) {
    std::cout << "the elements are :-" << std:: endl << '\t';
    for (int i = 0; i < arr.length; i++) {

        std::cout << arr.A[i] << ',';
    }
    std::cout << std::endl;
    
}

int ifSorted(int *a, int n, int i) {
    if (n >0) {
        
        if (*(a + i) > *(a + 1 + i))
            return -1;

           
        
        else {
            i++;
            ifSorted(a, n - 1, i);

        }
        return 0;
    }
    
}

int main()
{
    struct array arr = {{1,2,3,10,5,6,7}, 10, 7};
    int* p;
    
    std::cout << ifSorted(&(arr.A[0]), arr.length, 0);
}

I tried to debug the program and It works how it is supposed to but instead of returning -1 , it is returning 0.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source