Defining double exclamation?

前端 未结 7 1944
失恋的感觉
失恋的感觉 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.

提交回复
热议问题