Confused about tutorial coding

This is a discussion on Confused about tutorial coding within the C++ Programming forums, part of the General Programming Boards category; "What is !(1 && 0)? Of course, it would be TRUE. It is true is because 1 && 0 evaluates ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    25

    Confused about tutorial coding

    "What is !(1 && 0)? Of course, it would be TRUE. It is true is because 1 && 0 evaluates to 0 and !0 evaluates to TRUE (ie, 1). "
    This is from the tutorial, ok, first of all how does that make sense What is not 1 and 0?,
    that makes not sense to me because what is it being compared to?
    Help
    :S

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,666
    The NOT operator simply returns the inverse.

    If you apply it to true: !true == false.
    If you apply it to false: !false == true

    It's actually quite simple.

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    25
    That was great advice. I suggest you add that explanation to the tutorial.

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It's just to train you to understand boolean arithmetic. In practice you might be dealing with something like that:
    Code:
        int p = 20;
        if (!(p > 5 && p < 15))
        {
        }
    Looking at the code you see that the first comparison is true (1) and the second is false(0).
    Now, does that if branch get executed?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structures tutorial problem
    By Steve MacD in forum C Programming
    Replies: 3
    Last Post: 11-21-2005, 03:27 PM
  2. multi-threading tutorial
    By Ruski in forum C++ Programming
    Replies: 10
    Last Post: 07-16-2005, 03:02 PM
  3. Please review my first tutorial
    By Stan100 in forum C++ Programming
    Replies: 13
    Last Post: 06-22-2005, 03:06 PM
  4. Cprog tutorial: Design Patterns
    By maes in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2004, 01:41 AM
  5. Stencil Buffer Tutorial Port.. test me! (linux)
    By Perspective in forum Game Programming
    Replies: 3
    Last Post: 08-15-2004, 09:35 PM

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