You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Exercise 2.23: Given a pointer p, can you determine whether p points to a valid
object. If so, how? If not, why not?
By Faisal saadatmand
Yes. Any of the following methods would work:
if (p != nullptr) // preferred new C++ standard
if (p != 0)
if (p != NULL) // requires cstdlib header
if (!p)
if (p)
I suggest, fact that pointer p is not equals to nullptr (or 0 or NULL) doesn't say anything about validity of object it points to. I suppose, it is not possible to determine whether p points to a valid object (and even whether it point to any object at all).
The text was updated successfully, but these errors were encountered:
The answer to ex.2.23 says:
I suggest, fact that pointer p is not equals to nullptr (or 0 or NULL) doesn't say anything about validity of object it points to. I suppose, it is not possible to determine whether p points to a valid object (and even whether it point to any object at all).
The text was updated successfully, but these errors were encountered: