What would be a brief definition of a reference variable in C++?
A reference is an alternative label, an alias, for the object it is initialized with. Once a reference is initialized it can not be changed to be an alternative label or alias of some other object. After the initialization the reference or the object variable may be used interchangeably.
A reference has some of the characteristics of a const pointer to an object in that it is initialized when defined. And while what it references or points to can be changed, the reference or the const pointer itself can not be changed. However since a reference is an alternative label or alias it may or may not actually exist as a data object unlike a const pointer which will probably exist unless the compiler can optimize it away. And even if a reference is created as an actual entity by the compiler, that is compiler housekeeping and should be ignored since it officially does not exist much like the man behind the curtain in the Emerald City.
The following code samples gives examples comparing and contrasting reference with pointer and const pointer:
int myInt; // create a variable of type int, value not initialized
int myInt2 = 3; // create a second variable of type int with a value of 3
int &rInt = myInt; // create a reference to the variable of type int, myInt
rInt = 5; // myInt now has a value of 5, the reference is an alias for myInt
rInt++; // myInt now has a value of 6, the reference is an alias for myInt
rInt = myInt2; // myInt now has the same value as myInt2, a value of 3
int *pInt = &rInt; // pInt points to myInt
(*pInt)++; // increments myInt
pInt++; // increments the pointer which formerly pointed to myInt
int &rInt2; // error C2530: 'rInt2' : references must be initialized
int *pInt2; // just fine, uninitialized pointer is ok
int * const pInt3; // error C2734: 'pInt3' : const object must be initialized if not extern
int * const pInt4 = &myInt; // define and initialize const pointer
pInt4 = &myInt2; // error C3892: 'pInt4' : you cannot assign to a variable that is const
There are actually two kinds of references: an lvalue reference and an rvalue reference.
An lvalue reference is the same reference in the C++ language before C++11. An rvalue reference was introduced in C++11 to allow for a reference to a temporary object to assist with doing a move rather than a copy and some other actions where a copy is the wrong approach but a move is the right approach.
For example a comparison of lvalue reference and rvalue reference in the following simple source lines. Because these are int references that means that an assignment of a non-integer value results in the compiler doing a conversion which results in a temporary variable. An rvalue reference can bind to a temporary variable and an lvalue reference can not.
// assign a double to an int causing creation of temporary
int &rIntd1 = 1.2; // error C2440: 'initializing' : cannot convert from 'double' to 'int &'
int &&rIntd2 = 1.2; // warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
rInt = rIntd2; // myInt from the code above now has a value of 1, 1.2 was truncated when converting from double to int