The difference between using refrences(&var), and pointers(*var) is that using refrences is more efficent because you do not have to derefernce the object. Am I right, and if I am why use pointers then?
Take this code for example:
#include<iostream>
//function prototype
void rFunc(int &rNum);
void pFunc(int *rNum);
//main method
int main()
{
using std::cout;
using std::endl;
//SO all the variables w/ ref and pointers are initliazed
int age = 5;
int *pAge = &age;
int &rAge = age;
cout << "age: " << age << endl;
cout << "*pAge: " << *pAge << endl;
cout << "rAge: " << rAge << endl;
cout << "using rFunc function..." << endl;
rFunc(age); //Using refrence function
cout << endl;
cout << "now age: " << age << endl;
cout << "now *pAge: " << *pAge << endl;
cout << "now rAge: " << rAge << endl;
cout << "using pFunc function..." << endl;
pFunc(&age); //Using pointer function
cout << endl;
cout << "now age: " << age << endl;
cout << "now *pAge: " << *pAge << endl;
cout << "now rAge: " << rAge << endl;
system("PAUSE");
return 0;
}
void rFunc(int &rNum)
{
using std::cout;
using std::endl;
cout << "Setting age to 15..." << endl;
rNum = 15;
}
void pFunc(int *rNum)
{
using std::cout;
using std::endl;
cout << "Setting age to 55" << endl;
*rNum = 55;
}