Everything in c++ , including the STL containers are passed by value . But the exception is Array which are passed by pointers . Right?
Why are arrays in c++ [eg: int a[5] ] are passed by pointers but the vectors are passed by value ? [By default]
edit: okay , std::array can be passed by value also , I wasn't aware of this .
code :
void fun_array(int a[])
{
a[0]=10;
}
void fun_vector(vector<int> v)
{
v[0]=10;
}
int main()
{
int a[5]={1,2,3,4,5};
vector<int> v={1,2,3,4,5};
fun_array(a);
fun_vector(v);
cout<<a[0]<<" "<<v[0];
}
output : 10 1