what does !!a means in C programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dilip7597
    New Member
    • Dec 2009
    • 1

    what does !!a means in C programming

    Hello Guys,

    while checking one of the program, I found one difficulty with my program. there was a condition like (!!a), and I don't know what does it means. So if anybody knows about it then please help me out.

    Thanks,
    Dilip
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    The exclamation mark (!) is the logical "not" operator; for example, "!=". You have two of them strung together: !!a can be read as "not not a".

    The truth table for the ! operator is something like this:
    !(0) -> 1
    !(any nonzero value) -> 0

    Therefore, the double-not operator does this:
    !!(0) -> 0
    !!(any nonzero value) -> 1
    That is, it changes any nonzero value to "1".

    In my opinion, somebody was being overly clever.

    Comment

    • APmore
      New Member
      • Jul 2007
      • 14

      #3
      That sort of coding is OK.it depends on the context of coding.

      say he might be converting that decimal number to fit in binary logic.

      Comment

      Working...