With my compiler at least, creating a reference implies no dereferencing. Therefore, code like the following works:
int trivialExample(char* array, int length)
{
char& ref = array[6];
if (length > 6)
{
std::cout << ref << std::endl;
}
}
That is, given a char
array and its length (and assuming a bunch of trivialities like the array elements are all initialized and the passed length is correct), it will print the seventh character only if it actually exists.
Is this relying on undefined behavior?