|= operator in C++

This is a discussion on |= operator in C++ within the C++ Programming forums, part of the General Programming Boards category; what is function of |= operator in C++? like if we write a |= b; what does |= do here? ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    29

    |= operator in C++

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

    like if we write a |= b;

    what does |= do here?

    thanks.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

    --
    Mats
    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
    Location
    Singapore
    Posts
    23,773
    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, 02: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, 02:41 PM
  5. How come i dont work?
    By bluehead in forum C++ Programming
    Replies: 4
    Last Post: 01-20-2002, 10:39 PM

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