0

I've read everywhere that the references cannot be reassigned. but I am not getting the reason. Consider the below code

int x=11; // variable initialization  
int z=67;  
int &y=x; // y reference to x  
int &y=z; // y reference to z, but throws a compile-time error.  

Here, y References to x as an alias, so when we say &y=z now it should alias to z instead of y. why can't we reassign it?

StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458

0 Answers0