Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly incorrect answer to Exercise 2.23 #3

Open
lisenkoevg opened this issue Jan 6, 2025 · 0 comments
Open

Possibly incorrect answer to Exercise 2.23 #3

lisenkoevg opened this issue Jan 6, 2025 · 0 comments

Comments

@lisenkoevg
Copy link

The answer to ex.2.23 says:

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant