LoginSignup
0
0

More than 5 years have passed since last update.

【C++】`if(pointer != NULL)`の代わりに、`if(pointer)`が使えるよ

Posted at

null pointerはbooleanのfalseと解釈され、non-null pointerはtrueと解釈されるため、

if(pointer != NULL)の代わりに、if(pointer)`が使える。

(C++11にて確認済み)

参考: From the C++11 standard, section on Boolean Conversions:

A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to member type can be converted to a prvalue of type bool. A zero value, null pointer value, or null member pointer value is converted to false; any other value is converted to true . A prvalue of type std::nullptr_t can be converted to a prvalue of type bool ; the resulting value is false .

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0