
As a beginner Most of the time one gets confused, if both are referring to the same things then what exactly they are. Let’s find out with a real-world scenario.
We all have a real name and a calling name by which your friend might call you and an address where we live. So calling name is a reference to me, your can call me by my real name as well as calling name. The address is the pointer where I live. So to meet me you have to either call me by name or calling name or use address to visit my house.
#include <iostream>
using namespace std;
int main(){
string name = "Aditya" ; // Real Name
string &adii = name; // Calling name used by my friend
string *ptr = &name; // My address 0x7ffe8ab9a320
//<-------------Some Codes are in below section ----------------->
return 0;
}
You have three ways to meet me, in terms of the program you can access a variable in three different ways.
Note :- Reference variable must be initialized before compile , else who knows that you are know by other name too.
std::cout<<"Actual Name is " <<name<<endl;
std::cout<<"Reference Name is "<<adii<<endl;
std::cout<<"My Address is "<<ptr<<endl;
std::cout<<"Who lives at that address "<<*ptr<<endl;
Output
Actual Name is:- Aditya
Reference Name is :- Aditya
My Address is at:- 0x7ffe8ab9a320
Who lives at that address:- Aditya
Now you have to meet me in three different ways, why not change/Modify info.
//First you can directly modify using actual name
name = "Aditya G";
std::cout<<name<<endl;
// output -> Aditya G
//second ,using reference name
adii = "A Gaurav";
std::cout<<adii<<endl;
//output -> A Gaurav
//thrid, Using Pointer(Address)
*ptr = "Aditya Gaurav";
std::cout<<*ptr<<endl;
//output -> Aditya Gaurav
// Now even if you access variable by first two ways you will find out info is updated everywhere.
std::cout<<adii<<endl;
//output -> Aditya Gaurav
std::cout<<name<<endl;
//output -> Aditya Gaurav
Even if you forget by now you can remember it as Your Name is a variable, your calling name is reference [Your friends used to call you] and your address is pointer by which people come to meet you from remote.

I do love the manner in which you have presented this problem plus it does indeed give us a lot of fodder for thought. However, through everything that I have seen, I basically hope as the opinions stack on that individuals keep on point and not get started on a soap box regarding the news du jour. Anyway, thank you for this outstanding piece and whilst I can not necessarily agree with this in totality, I respect your standpoint.
LikeLiked by 1 person
Basically This post as well as upcoming post will be connected to each other, mostly for embedded developer. Thanks for your time to read. Visit again!!
LikeLike
fantastic submit, very informative. I’m wondering why the other experts of this sector don’t understand this. You should proceed your writing. I’m confident, you have a huge readers’ base already!
LikeLiked by 1 person
Thanks for visiting !!, Keep reading , This blog will give you view from Hardware prospective .
LikeLike
[…] thing you can notice is all pointer points to their type If you try to point to a different kind then you will get an […]
LikeLike
It抯 really a great and helpful piece of info. I抦 satisfied that you simply shared this useful information with us. Please keep us up to date like this. Thank you for sharing.
LikeLike
感谢您的访问,作为低级开发人员订阅有趣的东西。
LikeLiked by 1 person
Hello there, I found your blog via Google while looking for a related topic, your web site came up, it looks great. I have bookmarked it in my google bookmarks.
LikeLike
Thanks for visiting , Be there, more interesting things are coming up, You can’t find in webs.
🙂
LikeLiked by 1 person
[…] variables can reserve the same register and in such cases, they become alias of each other like the reference. However, they are diagnosed with a […]
LikeLiked by 1 person
This is a really good tip especially to those fresh to the blogosphere. Short but very accurate info… Many thanks for sharing this one. A must read post!
LikeLiked by 1 person