What is the difference between these two alternatives? Are there performance tradeoffs? Any help appreciated. Examples below.
Code://Pass by pointer
void negate(int * pn)
{
*n=-*n;
}
void func()
{
int m=10;
negate(&m);//pass m's address<
std::cout<<m<<std::endl; //display: -10
}
//Pass by reference
void negate(int & n)
{
>n=-n;//modifies caller's argument
}
void func()
{
int m=10;
negate(m);//pass by reference
std::cout<<m<<std::endl; //diplay: -10
}