From: "Luong Ngo" <luong.ngo@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: Using operator ! twice
Date: Fri, 29 Jun 2007 17:36:07 -0700 [thread overview]
Message-ID: <1b2aacd80706291736s18563893q83a19d0ae5662514@mail.gmail.com> (raw)
In-Reply-To: <1b2aacd80706291734y55b6e654i956767ae2a6f5e46@mail.gmail.com>
Hello,
I came across several times codes that use ! operator on an integer
variable. I am curious what is the purpose of using it twice.
For example:
int flag;
if( !! flag) {
//do something
}
The first ! operator will make !flag to be true if flag is 0, and if
we not again it become false, which is just exactly the same if we
just left it as
if(flag), since 0 is the same as false. Similar logic for non-0
value of flag. Then why do we need to use ! operator twice to get back
the same value as if we don't use at all? this seems to be the same
for me if we do this in math: -(-( -8)) = -8;
Any explanation would be appreciated.
Thanks,
-L
next parent reply other threads:[~2007-06-30 0:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1b2aacd80706291734y55b6e654i956767ae2a6f5e46@mail.gmail.com>
2007-06-30 0:36 ` Luong Ngo [this message]
2007-06-30 3:24 ` Using operator ! twice Pedro de Medeiros
2007-07-01 1:08 ` Glynn Clements
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1b2aacd80706291736s18563893q83a19d0ae5662514@mail.gmail.com \
--to=luong.ngo@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).