i was just learning c++ but i didnt understand the concept of function calling by name and by reference could anyone give me breif description or a link to a good c++ guide
When you Pass by Name your function simply copies the values you pass
into different variables and uses those for calculations, your original values/data
will always remain untouched because your function is using only the copies.
When you Pass by Reference the function will use the
actual data you pass in,
so any changes made to them during the function will remain for the rest of the program.
i.e.
void blah(int A)
{
A = 5000
}
void blah2(int &A)
{
A = 5000
}
the second will result in A being set equal to 5000,
the first will result in nothing. It will copy A, set that
copy equal to 5000 and then exit.
Fore example,
Code:
int Rawr = 80;
blah(Rawr);
cout << Rawr;
//Would display 80
blah2(Rawr);
cout << Rawr;
//Would display 5000
|
yeah thanks its more clear now