What does vertical pipe (|) mean in C ++?

I have this C ++ code in one of my programming books:

WNDCLASSEX wndClass = { 0 }; wndClass.cbSize = sizeof(WNDCLASSEX); wndClass.style = CS_HREDRAW | CS_VREDRAW; 

What makes a single channel in Windows C ++ programming?

+7
source share
3 answers

Bitwise OR operator. It will set all true bits that are true in either of both of the provided values.

For example, CS_HREDRAW may be 1 and CS_VREDRAW may be 2. Then it is very simple to check if they are set using the bitwise AND & operator:

 #define CS_HREDRAW 1 #define CS_VREDRAW 2 #define CS_ANOTHERSTYLE 4 unsigned int style = CS_HREDRAW | CS_VREDRAW; if(style & CS_HREDRAW){ /* CS_HREDRAW set */ } if(style & CS_VREDRAW){ /* CS_VREDRAW set */ } if(style & CS_ANOTHERSTYLE){ /* CS_ANOTHERSTYLE set */ } 

See also:

+21
source

| called the bitwise OR operator .

|| called the logical operator OR.

+7
source

This is a bitwise OR operator. For example,

 if( 1 | 2 == 3) { std::cout << "Woohoo!" << std::endl; } 

will print Woohoo! .

+4
source

All Articles