I am a beginner and puzzled by the uses of reference. I have been studying a lot on pointer. Recently, I start working on reference. Can I summarize reference in a sentence like that "what references can do, can be done with using pointers"
As I see, pointer store an memory address, so we can go into specific address to do things but reference doesn't even take a memory, it's just a alias.
Here is pointer implement
#include <iostream>
using namespace std;
void Increment(int* value)
{
(*value)++;
}
int main()
{
int a = 8;
int* ptr_a = &a;
Increment(ptr_a);
cout << a << endl;
std::cin.get();
}
and here is reference implement
#include <iostream>
using namespace std;
void Increment(int& value)
{
value++;
}
int main()
{
int a = 8;
int& ref_a = a;
Increment(ref_a);
cout << a << endl;
std::cin.get();
}
I get the exactly same output. As a result, can I conclude the differences as "Pointers cover all the function of references"?
Thank you