How the output are not same for both array and vector?

Find the output of the following code

void changing(int a[],int size)
{ for(i=0;i<size();i++)
    a[i]=a[i]+1; }

void change(vector<int> v)  
{   for(i=0;i<v.size();i++)
    v[i]=v[i]+1;    }

int main()
{   int a[3]={0,1,2}; vector<int> v;
for(i=0;i<3;i++)
    v.push_back(i);
changing(a,3);
change(v);
for(i=0;i<3;i++)
    cout<<a[i]<<” ”;
   for(i=0;i<3;i++)
   cout<<v[i]<<” ”;         

}

@gopinathsah24
Hello Gopi,
case 1-> changining function
In this case array is passed as reference (i.e address) so whatever changes changing function will make in array a[] will be reflected in the sent array.
case 2 -> change function
In this case vector is passed as value (i.e sent vector is copied to new vector) and whatever changes change function will make it will occur in newly copied vector and not in original sent vector that’s why u are getting different outputs

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.