Not Operator in C++

Discussion in 'Computer Science & Culture' started by S.Tarafdar, Jun 26, 2003.

Thread Status:
Not open for further replies.
  1. S.Tarafdar Registered Senior Member

    Messages:
    35
    Dear All,
    I am running with this simple problem:
    I know % is a modulo operator which calculates remainder (int/int).
    For example:5%2=1.
    Then how does the following work?
    if(!(10%2)) cout<<"10 divisible by 2"<<endl;
    10%2=0,so, !0 means what?

    Thanks
    S.Tarafdar
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. AntonK Technomage Registered Senior Member

    Messages:
    1,083
    It means just that...not.

    When you dont have a subject, not can be implied to mean no true. In C and C++, not true is false, and false is 0. It depends on the computer i believe, but true is anything EXCEPT 0. So when you do !(10%2) you ask saying (10%2) == 0.

    -AntonK
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. S.Tarafdar Registered Senior Member

    Messages:
    35
    Still confused!

    Dear AnTonk,
    Thank you for your reply.However,I have still confusion.10%2 is a NULL(0),that is why it is false.So,!0 i.e. NOT False is True,isn't it?So,how does it work?

    Regards
    S.Tarafdar
     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. SG-N Registered Senior Member

    Messages:
    1,051
    So... I don't understand what you are asking AntonK!
    He already explained you the fact that !(10%2) == !0 == !(false) == true.
    0 == false when it's in a condition (if, while, for...)! What do you want to know now? How it is working in the binary or electronic part?! :bugeye:

    Have a nice day.

    Please Register or Log in to view the hidden image!

     
Thread Status:
Not open for further replies.

Share This Page