There is no such concept as a constant-to-reference because a reference itself is not an object; it is an alias to an existing object. Therefore, a reference cannot be const. The term "reference to const" (or "const reference") refers to a reference that points to a const object, preventing modification through that reference.
A reference to const can be initialized with a literal value, whereas a mutable reference cannot.
int& mutable_ref = 42; // Invalid: mutable reference requires an lvalue
const int& const_ref = 42; // Valid: const reference can bind to a literal
A reference to const can bind to a mutable object, but it cannot be used to modify that object. Conversely, a mutable reference cannot bind to a const object.
int mutable_value = 100;
const int const_value = 200;
int& mut_ref_to_const = const_value; // Invalid: cannot discard const qualifier
const int& const_ref_to_mutable = mutable_value; // Valid
const_ref_to_mutable = 50; // Invalid: cannot modify through const reference
When a reference to const is bound to a mutable variable, it disallows modifications through that reference. However, a separate mutable reference bound to the same variable can modify it.
A reference to const can bind to the results of expressions involving both mutable and const references, while a mutable reference cannot.
int a = 10;
const int c = 20;
int& r1 = a;
const int& r2 = c;
const int& r3 = r1 + 5; // Valid: binds to a temporary const int
const int& r4 = r2 * 3; // Valid: binds to a temporary const int
int& r5 = r1 + 5; // Invalid: mutable reference requires an lvalue
int& r6 = r2 * 3; // Invalid: mutable reference requires an lvalue
A reference to const can bind to variables of a different type, which involves an implicit conversion. A mutable reference cannot do this.
double d_val = 99.0;
const int& int_ref_to_double = d_val; // Valid: implicit conversion
int& mut_ref_to_double = d_val; // Invalid: cannot bind to different type
When binding a reference to const to a variable of a different type, the compiler performs an implicit conversion and creates a temporary. The actual process is equivalent to:
double d_val = 99.0;
// The compiler generates a temporary const int from the double
const int temp = d_val;
const int& int_ref_to_double = temp;
This temporary creation allows the type conversion. A mutable reference does not support this behavior, as it would require modifying a temporary, which is not meaningful.