Why references can not be reinitialized in C++ while pointers can be reinitialized?
int x=5;
int y=6;
int *p1;
p1 = &x;
p1 = &y; //re-initializing the pointer but same can not be done with references
int &r1 =x;//can be initialized only once
Why references can not be reinitialized in C++ while pointers can be reinitialized?
int x=5;
int y=6;
int *p1;
p1 = &x;
p1 = &y; //re-initializing the pointer but same can not be done with references
int &r1 =x;//can be initialized only once
There's no obvious syntax. You can't use the normal =
syntax; that sets the value the underlying pointer of the reference. Perhaps you could think up a syntax like this:
&my_reference = new_value;
But that's kind of strange and awkward.