logic ops,

Discussion in 'C++' started by vsgdp, Sep 7, 2006.

  1. vsgdp

    vsgdp Guest

    bool a =false;
    bool b=true;
    cout << (a || b) && false;
    cout.operator <<((a || b) && false);

    The first cout outputs true. The second one false. Why not both false?
    vsgdp, Sep 7, 2006
    #1
    1. Advertising

  2. vsgdp

    Marcus Kwok Guest

    vsgdp <> wrote:
    > bool a =false;
    > bool b=true;
    > cout << (a || b) && false;
    > cout.operator <<((a || b) && false);
    >
    > The first cout outputs true. The second one false. Why not both false?


    Order of operations. The first one does "cout << (a || b)" first, which
    returns a reference to the stream (cout). Then it does "cout && false"
    and discards the result.

    It should do what you think if you add an extra set of parentheses:

    cout << ((a || b) && false);

    --
    Marcus Kwok
    Replace 'invalid' with 'net' to reply
    Marcus Kwok, Sep 7, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wendy S
    Replies:
    3
    Views:
    3,153
    Blah Blah
    Jul 13, 2003
  2. Glen Able
    Replies:
    4
    Views:
    435
    Attila Feher
    Jan 28, 2004
  3. Sergey
    Replies:
    6
    Views:
    2,912
    Victor Bazarov
    Apr 1, 2005
  4. jalkadir

    overloaded ops << and >>

    jalkadir, Jun 30, 2005, in forum: C++
    Replies:
    10
    Views:
    568
    Old Wolf
    Jul 4, 2005
  5. Replies:
    15
    Views:
    820
Loading...

Share This Page