Why is call by reference faster than call by value?

Q4. STL+NumberTheoryQ4
Which code will take more time :
Code A:

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

Code B:

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

The answer to this is : A has more time complexity than B ,Explain why call by reference is faster than call by value

Hey @deepak_four ,
It is because in call by value for the above example apart from executing the function the function also copies the vector passed as argment but in call by reference there is no copying of arguments involved.
Therefore, the time complexity of Code A increases due to the copying of vector .
Hope it clears your doubt
Happy Coding :slight_smile: