I'm looking at some c++ code that involves addresses and came across some lines that I don't understand.
#include <iostream>
int main()
{
int x = 5;
int &R = x;
//int &R = &x; // ERROR!
std::cout << "R address: " << &R << "\n";
std::cout << "R number: " << R << "\n";
}
The code works as expected, however I don't understand the line where the variable x is assigned to the address of R. My understanding is that this would be an error since you're assigning the value stored in x to an address. How come the line that is commented out returns an error?