As you can see in the example I'm about to provide below I'm using both Pass By Reference and Pass By Address...
#include<iostream>
#include<string>
void passByAddress(int *a);
void passByReference(int &a);
int main() {
int betty = 21;
int setty = 45;
passByAddress(&betty);
passByReference(setty);
std::cout << "Betty : " << betty << std::endl;
std::cout << "Setty : " << setty << std::endl;
}
//Pass By Adress
void passByAdrress(int *a) {
*a = *a + 5;
//Memory Adress of a.
//So gives hexa decimal.
std::cout << "Address : " << a << std::endl;
//Actual Value of adress
std::cout << "Address's Value : " << *a << std::endl;
}
//Pass By Reference
void passByReference(int &a) {
a = a + 5;
//Memory Address of a.
//So gives hexa decimal.
std::cout << "Adrress : " << &a << std::endl;
//Actual Value of address
std::cout << "Address's Value " << a << std::endl;
}
So here I really don't understand the difference in using passbyaddress and passbyreference..Although i do understand the differences between these both and Pass By Value(As pass by value passes the copy of variable not memory address), I don't understand whats the difference of these both. Many people just say "Use Pass By Reference its much better", or "Use Pass By Reference all the time except when you have to use Pass By Address".. But I want to know the real difference so i can decide which one to use in my later projects.
Thankyou.