Thread: Why does this statement print a 0?

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    18

    Why does this statement print a 0?

    Code:
    #include <stdio.h>
    
    main ()
    {
    printf(" %x", !0xabababababab );
    }
    This prints out a 0 and I'm not sure why. Any insight? Thanks!

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    0x is a prefix for hexadecimal numbers.
    a,b are valid hex digits, so it is a number which is not 0.

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,508
    To expand on manasij7479's comment:

    Code:
    non-zero value == true
    zero value == false
    
    !(non-zero value) == !(true)  == false == 0
    !(zero value)     == !(false) == true  == 1

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    And to add to that, if you were trying to do bitwise NOT, that's ~.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Print statement won't print
    By Sakari in forum C Programming
    Replies: 17
    Last Post: 06-20-2012, 06:41 PM
  2. Having troubles with a simple print statement.
    By Tails in forum C Programming
    Replies: 4
    Last Post: 09-22-2011, 06:14 PM
  3. Replies: 1
    Last Post: 07-15-2011, 10:46 AM
  4. bizarre print statement glitch
    By spongefreddie in forum C Programming
    Replies: 4
    Last Post: 09-23-2010, 10:39 AM
  5. Overwriting last print statement in command line
    By PolarBear2k in forum C Programming
    Replies: 2
    Last Post: 11-09-2006, 03:08 PM