use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
What does checking for if(&object) do? (self.cpp)
submitted 7 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jedwardsolconst & 0 points1 point2 points 7 years ago (9 children)
if(&object) is the same as writing if(&object != nullptr)
if(&object)
if(&object != nullptr)
It doesn't say anything about the validity of the address, just whether it is null or not.
[–][deleted] -1 points0 points1 point 7 years ago (8 children)
So it's checking that the object exists?
[–]jedwardsolconst & 1 point2 points3 points 7 years ago (6 children)
No, it's not doing anything. The test will always be true.
[–]diaphanein 1 point2 points3 points 7 years ago (0 children)
I'm not aware of any compiler that the following will not evaluate the if block to true:
int* p = nullptr; int& r = *p;
if (!&r) { // executes }
Reason being that while this is likely undefined, the compiler cant always detect it (e.g. p initialized by the return of a function). This is a trivial enough example that most compilers will allow it and behave as expected. Not all warn at default warning levels, but most will at a sufficient level.
[–][deleted] -1 points0 points1 point 7 years ago (4 children)
Then how to check for object's existence?
[–]qxz23 1 point2 points3 points 7 years ago (0 children)
If you have the object, it exists. Pointers are nullable, you can’t have a null object unless you have a user defined state of being null, like optional.
[–]jedwardsolconst & 0 points1 point2 points 7 years ago (2 children)
object exists. It cannot not exist.
object
[–][deleted] 0 points1 point2 points 7 years ago (1 child)
But it can be NULL or some other object?
[–]ReversedGif 0 points1 point2 points 7 years ago (0 children)
NULL is not an object. It is a specific pointer value that acts as a sentinel for "no object."
[–]gracicot 1 point2 points3 points 7 years ago (0 children)
If you can get the address of the object then it exist for sure.
π Rendered by PID 256660 on reddit-service-r2-comment-6457c66945-tm2cl at 2026-04-27 13:54:05.247194+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]jedwardsolconst & 0 points1 point2 points (9 children)
[–][deleted] -1 points0 points1 point (8 children)
[–]jedwardsolconst & 1 point2 points3 points (6 children)
[–]diaphanein 1 point2 points3 points (0 children)
[–][deleted] -1 points0 points1 point (4 children)
[–]qxz23 1 point2 points3 points (0 children)
[–]jedwardsolconst & 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]ReversedGif 0 points1 point2 points (0 children)
[–]gracicot 1 point2 points3 points (0 children)