Why is Vector not maintaining itself during function call

using namespace std;

int all_occ(int *arr , int key , int n , vector pos){

if(n==0){
    return -1;
}

int p = all_occ(arr+1 , key , n-1 , pos);


for(size_t i = 0 ; i<pos.size() ; i++){
    pos.at(i)++;
}

if(arr[0] == key){
    pos.push_back(0);
    return 0;
}

if(p==-1){ 
    return -1;
}


return 0;

}

int main(){

int arr[] = {1,2,3,4,7,8,7,11,12,7};

int key = 7;
// cin>>key;
vector<int> pos ;
pos.reserve(10);
all_occ(arr,key, sizeof(arr)/sizeof(arr[0]) , pos);

for(int i : pos){
    cout<<i <<endl;
}

}

above is my code for finding max occurrence in an array, but when this function is returning an empty vector.

but if I try declaring vector as global this is working fine.

why is vector pos not able to maintain itself when returning from the function.

this may happen because you may have not passed the vector by reference

i can’t see how you have passed so always try to send the link of code

if even after passing vector by reference it doesn’t work or you need more clarification feel free to ask

is your doubt resolved??

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.