For example:
object* pObject = nullptr;
OR:
object* pObject = 0;
Again, which one is better performance wise?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
nullptris of typestd::nullptr_tand so the constructor be overloaded. This means the fact that it is null is encoded in the type, so it can be theoretically faster by avoiding a conditional.Pointers obviously don’t have overloaded constructors so whether you use
0ornullptris irrelevant. Same machine code, same performance.Anyway, go with
nullptrwhen you want a null pointer. Be careful of0as it will call integer overloads rather than pointers.