c++ - Are references or pointers faster? -
from know, references name variable whilst pointers own variable. pointers take space. people "use reference or pointer" don't better. if references take no memory of own, references win in department. don't know if compiler makes distinction between references , normal variable. if operations on reference, compile same code normal variable?
internally references implemented in terms of pointer. so, it's difficult faster pointer/reference.
it's usage of these 2 makes difference.
for example want pass reference parameter function.
void func(int& a) case_1 { //no need check null reference... } void func(int* a) case_2 { //need o check if pointer not null }
in case_2 have explicitly check if pointer not null before dereferncing whereas that's not case references because references initialized something.
assumption playing game in civilized manner i.e
you not doing like:-
int*p = null; int &a = *p;
Comments
Post a Comment