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:
Assignment *a;
if (!getAssignment(query, a))
return false;
hasSolution = !!a;
if (!a)
return true;
How do I know what value will the double exclamation mark result in ? In other words does it always convert to true ? false ? or can you define a behavior for it such as executing a method to determine the result (how does the object know how to act in this situation) ? I am bit confused about this piece of code due to all these exclamation stuff going on.. Any explanation is appreciated.
Hope I was clear and thanks.
It is used to end a rhetorical question or a simultaneous question and exclamation. Some writers, then, began using multiple exclamation points as a logical outgrowth of the interbang and single exclamation mark to add even more emphasis to words, phrases, and sentences.
Use the number of exclamation points that's in your heart. Language is supposed to help you communicate what you mean, so if you need two exclamation points for an extra-emphatic opinion and 27 for an announcement to your brother about your promotion, go for it.
No! An exclamation point (or mark) is used after an interjection or to show emphasis or strong emotion.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With