3 ms·
Note that I was talking about using pointers to pass a single object by reference. In such cases references are 100% better than pointers, if the pointer is nev
by fluoridation 4y ago
Note that I was talking about using pointers to pass a single object by reference. In such cases references are 100% better than pointers, if the pointer is never supposed to be null.
>Also, there are programming errors that can lead to a NULL reference, and there is no way to guard against that in code using the reference (well, none that doesn't generate Warnings, and/or is liable to be optimized out) - whereas at least with pointers you can always check in your own code.
On the other hand, if you find you've received a null reference as a parameter then you know that something has definitely gone wrong, because unlike with pointers null references are impossible in the absence of UB. If all you know is that the function has received a null pointer then you could waste a lot of time trying to figure out how the program reached that state, when in actuality the problem is that someone else wrote out of bounds.