Code Explanation

This is a discussion on Code Explanation within the C Programming forums, part of the General Programming Boards category; Can someone explain what the exclamation mark in the following function does? Code: /* Multiple function definition */ int multiple( ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    42

    Code Explanation

    Can someone explain what the exclamation mark in the following function does?

    Code:
    /* Multiple function definition */
    int multiple( int num1, int num2 )
    {
    
        return ! ( num2 % num1 ); /* Returns true or false */
        
    } /* End function hypotenuse */
    Thanks

    DMKanz07

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    The result of the logical negation operator ! is 0 if the value of its operand compares unequal to 0, 1 if the value of its operand compares equal to 0. The result has type int. The expression !E is equivalent to (0==E).
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 08:23 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 11:20 AM
  3. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21