Thread: |= operator in C++

  1. #1
    Registered User
    Join Date
    Sep 2007

    |= operator in C++

    what is function of |= operator in C++?

    like if we write a |= b;

    what does |= do here?


  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    If we assume that a and b are integer, then a |= b is the same as a = a | b, which is a bitwise or - so all bits that are set in b gets set in a as well.

    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
    Read the tutorial on bitwise operators. a |= b is short hand for a = a | b.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is |= operator ?
    By blue_gene in forum C++ Programming
    Replies: 12
    Last Post: 05-06-2004, 10:13 AM
  2. Swap a bit
    By mr_nice! in forum C Programming
    Replies: 7
    Last Post: 03-01-2004, 03:15 AM
  3. bit shifting
    By Nor in forum C++ Programming
    Replies: 9
    Last Post: 08-08-2003, 11:55 AM
  4. Colours?
    By Fountain in forum C++ Programming
    Replies: 7
    Last Post: 01-29-2002, 03:41 PM
  5. How come i dont work?
    By bluehead in forum C++ Programming
    Replies: 4
    Last Post: 01-20-2002, 11:39 PM