Thread: so confused - learning something

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    3

    so confused - learning something

    Im going through the C++ Tutorial and i am on page 2. Im having trouble understanding the following problem...

    !( ( 1 || 0 ) && 0 ) (answer is 1 but how?)

    what i see is...

    not 1 or 0 and not 0
    so i dont understand how they get one...explanation please?

  2. #2
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Do brackets first:

    = !( ( 1 || 0 ) && 0 )
    //1 || 0 - is either 1, yes, the left is, so its true (1)

    = !( 1 && 0 )
    //1 && 0 - are both sides 1?, no, so its false (0)

    = !(0)
    //remove the backets to simplify

    = !0
    //what is the opposite of 0 (NOT 0), its 1.

    = 1
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    3
    = !( ( 1 || 0 ) && 0 )
    //1 || 0 - is either 1, yes, the left is, so its true (1)

    i dont get how 1 || 0 like you stated above is one..what i see is..not 1 or 0...so wouldnt it be 0?

  4. #4
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by marky03
    = !( ( 1 || 0 ) && 0 )
    //1 || 0 - is either 1, yes, the left is, so its true (1)

    i dont get how 1 || 0 like you stated above is one..what i see is..not 1 or 0...so wouldnt it be 0?
    No no no.. its like math, you do whats in the brackets () first, before worrying about what it says outside them. You'll also notice its ! ( ( , theres 2 backets, so the ! NOT symbol has no effect ever on ( 1 || 0 ).

    = !( ( 1 || 0 ) && 0 )
    //1 || 0 - is either 1, yes, the left is, so its true (1)

    do the contents of the bolded bracket first, then replace that part with the outcome, which is 1.

    Leaving !( 1 && 0 ), do the contents of the brackets first, is it 1 && 1? no, then it must be false (which is 0), so replace the bracketted part with 0.

    Leaving you with !0, NOT 0 is 1.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    3
    I now get it! Thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie ~ a problem with learning C++
    By ultrablade12 in forum C++ Programming
    Replies: 23
    Last Post: 08-04-2008, 04:05 PM
  2. Thinking about learning something else
    By tiachopvutru in forum A Brief History of Cprogramming.com
    Replies: 31
    Last Post: 06-24-2008, 02:45 PM
  3. Confused with array size
    By desmond5 in forum C Programming
    Replies: 4
    Last Post: 12-04-2007, 05:14 PM
  4. New to C++ and confused by boolean and ifs and else
    By jconner in forum C++ Programming
    Replies: 10
    Last Post: 08-02-2006, 03:29 AM
  5. Looking for good beginner tutorials in learning windows api
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 10-30-2001, 06:42 AM