Defining double exclamation?

前端 未结 7 1943
失恋的感觉
失恋的感觉 2021-02-04 06:43

I understand what a double exclamation mark does (or I think I understand) but I am not sure how it is defined on a random object. For example in the code snippet below:

相关标签:
7条回答
  • 2021-02-04 07:17

    a is a pointer. In C++, nullptr is defined to be an invalid pointer. !pointer turns a nullptr pointer into true and a non nullptr pointer into false. !boolean turns true into false and false into true. It will always work.

    !(!a) is a useful way to think of it.

    0 讨论(0)
提交回复
热议问题