Passing an array to a function with an odd format - "v + last + 1"

In programming practice, in the chapter on quicksort, there is some C code that looks at the basic algorithm for quicksort (I compiled the code into a program that prints arbitrary array values ​​before and after sorting):

#include<stdio.h>
#include<stdlib.h>

void swap(int v[], int i, int j)
{
    int temp;

    temp = v[i];
    v[i] = v[j];
    v[j] = temp;
}

void quicksort (int v[], int n)
{
    int i, last;
    if (n <= 1)
        return;
    swap(v, 0, rand() % n);
    last = 0;
    for (i = 1; i < n; i++) 
    {
        if (v[i] < v[0]) 
        {
            swap (v, ++last, i);
        }
    }
    swap(v, 0, last);
    quicksort(v, last);
    quicksort(v+last+1, n-last-1);
}

void printIntegerArray(int arrayInput[], int arraySize)
{
    for (int i = 0; i < arraySize; i++)
    {
        printf("%d ", arrayInput[i]);
    }
    printf("\n");
}

int main(void)
{
    int array[5] = {7, 10, 14, 12, 4};
    int arraySize = sizeof(array) / sizeof(array[0]);
    printf("Before sorting: ");
    printIntegerArray(array, arraySize);
    quicksort(array, arraySize); 

    printf("After sorting: ");
    printIntegerArray(array, arraySize);
}

I understand everything except the second recursive call:

quicksort(v+last+1, n-last-1);

What does "v + last + 1" do? I would not have expected C to resize the array at runtime, is it easy to say that the input is "an array starting at V [last + 1]" or is it something else? As always, sorry if I missed this on another post. I tried a multiple choice search of my question.

+4
2

, ", V [last + 1]" - ?

, , , , .

. , v , , . v+last+1 - , last+1 v.

+4
quicksort(v+last+1, n-last-1);

quicksort(&v[last+1], n-last-1);
+2

Source: https://habr.com/ru/post/1529752/


All Articles