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:
Don't think of it as "double exclamation mark", think of it as two separate operators, one running on the result of the other.
For all primitive types, it will "work". !a
is equivalent to a == 0
, so !!a
is equivalent to !(a == 0)
, which in turn is equivalent to a != 0
.
For user-defined types, it won't compile unless they overload operator !
. But obviously, in this case, the behaviour could be almost anything.