Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #73856

Re: What is the value after operator '!'?

From Richard Heathfield <rjh@cpax.org.uk>
Newsgroups comp.lang.c
Subject Re: What is the value after operator '!'?
Date 2015-10-26 14:04 +0000
Organization A noiseless patient Spider
Message-ID <n0lbpc$op5$1@dont-email.me> (permalink)
References <7229ebda-7352-441e-9946-ccee1ce81b03@googlegroups.com>

Show all headers | View raw


On 26/10/15 13:21, fl wrote:
> Hi,
>
> I saw coding such as: a=!a before. Today, when I write my code below, I find
> if on_off_flag==0, on_off_flag will be '1' after
>
>    on_off_flag = !on_off_flag;
>
> It is a surprise to me. I supposed it will be 0xFFFF,FFFF for integer
>   on_off_flag
>
> '!' is an inverse operator or not?

It's the logical inverse.

!anynonzerovalue is 0, and !0 is 1, by definition.

If you want bitwise inverse, use ~ and be careful.

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

What is the value after operator '!'? fl <rxjwg98@gmail.com> - 2015-10-26 06:21 -0700
  Re: What is the value after operator '!'? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-10-26 09:29 -0400
  Re: What is the value after operator '!'? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-26 13:42 +0000
    Re: What is the value after operator '!'? supercat@casperkitty.com - 2015-10-26 07:53 -0700
      Re: What is the value after operator '!'? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-26 17:37 +0000
        Re: What is the value after operator '!'? Keith Thompson <kst-u@mib.org> - 2015-10-26 11:05 -0700
          Re: What is the value after operator '!'? supercat@casperkitty.com - 2015-10-26 11:38 -0700
            Re: What is the value after operator '!'? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-10-26 20:27 +0000
              Re: What is the value after operator '!'? supercat@casperkitty.com - 2015-10-26 14:16 -0700
                Re: What is the value after operator '!'? Keith Thompson <kst-u@mib.org> - 2015-10-26 17:15 -0700
              Re: What is the value after operator '!'? Keith Thompson <kst-u@mib.org> - 2015-10-26 17:12 -0700
            Re: What is the value after operator '!'? Ian Collins <ian-news@hotmail.com> - 2015-10-27 10:27 +1300
            Re: What is the value after operator '!'? Keith Thompson <kst-u@mib.org> - 2015-10-26 15:15 -0700
              Re: What is the value after operator '!'? supercat@casperkitty.com - 2015-10-26 16:16 -0700
                Re: What is the value after operator '!'? Keith Thompson <kst-u@mib.org> - 2015-10-27 08:39 -0700
  Re: What is the value after operator '!'? Richard Heathfield <rjh@cpax.org.uk> - 2015-10-26 14:04 +0000
  Re: What is the value after operator '!'? Geoff <geoff@invalid.invalid> - 2015-10-26 09:50 -0700

csiph-web