Answer the question
In order to leave comments, you need to log in
How to use an array in recursion (C++)?
In a recursive function, I need to constantly interact with one array and change its contents depending on the results of the function, but the righteous compiler indicates that it is impossible to take and push the array into the function condition again like this.
I know that somehow it is possible to implement this using pointers, but I do not understand how. Explain, please.
Answer the question
In order to leave comments, you need to log in
You seem to be trying to pass the entire array in each function call.
This is not so easy to do, and, in fact, not what you need, because a copy will be transferred, and you want to change the original array.
The pointer is used like this:
int arr[32];
size_t index = 0;
recursive(&arr, index);
...
recursive(int **arr, index) {
if(index < 32) {
(*arr)[index] = 1;
recursive(arr, ++index);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question