Why is this condition invalid in C language?

clipboard.png

DEBUG

clipboard.png

LLDB

clipboard.png

I have judged whether it is empty or not here. Debug saw that the result is NULL, but executed it into if. Is there any negligence? the bosses give us some advice

.
C cPP
Jul.29,2021

nullptr


use nullptr instead of NULL,NULL in CPP to represent 0 hr class= nullptr is the realization of nullptr_t


essentially 0, NULL and nullptr
1) 0 is an int literal constant
2) NULL is a preprocessing variable defined in cstdlib, and its value is 0
3) nullptr is a literal value of nullptr_t type.
literally, NULL is a null pointer constant, while in CPP NULL extends to a constant of 0, which is int. So the constant 0 is both an integer constant and an empty pointer constant. The CPP11 standard introduces the keyword nullptr, which, as a null pointer constant, is a constant of type nullptr_t, which defines a conversion operator to any pointer type, and does not allow objects of that type to convert to non-pointer types.

Menu