It is not possible to assign an integer value to a reference variable directly, say like:
int &x=10; //not possible
Is there any other way we can modify this statement to make it possible?
But not like this:
int a=10;int &x=a;
This works fine. But I want some other way or modify a little bit my expression and make it work!
The reason it doesn’t work is because 10 is of the type “const int”. You can turn that into a reference, but you can’t make it non-const without violating some logic at the least.
that’ll work.
will also compile, but you can’t modify b (as that would imply modifying the actual “10” value).