I have run and this function prints all the element of the specified array. But I really do not understand how this function works so that I can print all elements of an array.
Can anyone give me a clear explanation, please?

11 Answers
11

&a[1] is the address of the second element of the array, which is effectively the address of the portion of the array after the first element. So after printing the first element of the parameter array,

print(&a[1], n-1);

passes itself the remaining portion of the array, decreasing the length by one as well.

For example, if you call print with the array {1, 2, 3, 4, 5} and n == 5, the chain of events and calls is the following:

This function takes as arguments the remaining part of the array and how many elements it contains. Every time you print the first element and then call recursively of the remaining part. Here is an example:

If n is zero (or less), it does nothing, so recursion stops. If n > 0, then it prints a[0] and calls itself recursively with n-1 for n (so that goes to 0 as the recursion proceeds) and &a[1] for a, i.e. it increments the pointer a in each recursive call. Remember that an array argument in C is syntactic sugar for a pointer argument.

why? well, the recursion always looks at the first element and prints it, and them advances to the next element by looking at the array from the 2nd element (which will now be the 'first', in the next iteration).
your stop condition is when no more elements are left - i.e. an array of length 0.

&a[1] gets a pointer to the first element of the array. Arrays and pointers are usable interchangably so when this is passed to the function the function can treat it as a new array, starting from the second element of the previous array, and with a length one less.