Reputation: 39
I am relatively new to C++. Here is a if statement I can not understand.
if ((ObjPtr = NewObjPtr) != NULL)
{
...
}
What is the "!= NULL" checked for?
Thanks.
Upvotes: 2
Views: 249
Reputation: 19860
In C++ an expression like myVar = 5
would return 5.
So basically this syntax is checking if NewObjPtr is not NULL.
You could say the value of an assignment is passed on to the left.
Upvotes: 1
Reputation: 43098
Every operand in C(C++) returns the result of the operation. For the '=' operator the result is the value assigned. So, the checking if for NULLness of ObjPrt and NewObjPrt.
Upvotes: 1
Reputation: 55554
This assigns NewObjPtr
to ObjPtr
and checks if ObjPtr
is non-null.
It is equivalent to the following:
ObjPtr = NewObjPtr;
if (ObjPtr != NULL) { ... }
Upvotes: 11