Thread: Confused by '&' oparator

  1. #1
    Registered User
    Join Date
    Dec 2007

    Confused by '&' oparator


    What is the '&' oparator in this statement?

    cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ;

    "reference", "bitwise" or "address of" operator?

    I think it cant be "reference" and "address of" because it wasnt declared.

    But if it "bitwise" oparator, where is the second argument?
    Compiler MSVC++ 2013 with Code::Blocks.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    It's a bitwise and, and the second argument is 1.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    It is bitwise and. That parenthesized expression can be expressed as: ((tm.tmPitchAndFamily & 1) ? 3 : 2).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Dec 2007
    Thank you Matsp and Laserlight, i understand it now.

    What confused me was the missing parentheses inside (( tm.tmPitchAndFamily & 1) ? 3 : 2).

    Next time im gonna imagine it there if i see an expression like that.
    Compiler MSVC++ 2013 with Code::Blocks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused about Memory
    By gL_nEwB in forum C++ Programming
    Replies: 22
    Last Post: 06-20-2006, 07:32 PM
  2. Confused
    By jeev2005 in forum C Programming
    Replies: 5
    Last Post: 06-01-2006, 02:04 PM
  3. So Now Im getting confused?!?!?
    By zergdeath1 in forum C++ Programming
    Replies: 11
    Last Post: 03-06-2004, 05:41 PM
  4. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of
    Replies: 4
    Last Post: 05-04-2003, 01:21 PM
  5. Extern Question, really confused
    By SourceCode in forum C Programming
    Replies: 10
    Last Post: 03-26-2003, 11:11 PM