The principle is that instead of storing the index on the element to be checked, since arr
is a pointer and changing it will not change the data, instead, you can use arr
as an iterator for the data in the array.
So, *arr < 0
checks if the current pointed element is negative (it will give 1
if yes, 0
if not), and ++arr
increases the cursor to the next place in the array, which is then recursively passed to check the rest of the array.
This is a very famous idea in functional languages ββthat work with lists, where you often work on the first element of the list (head) and recursion in the remaining list (tail).
source share