C++ compl Keyword
Example
The compl keyword gives the same result as the ~ operator:
int x = 6;
cout << (compl x) << "\n";
cout << (~x);
Definition and Usage
The compl keyword is another way to write the bitwise ~ operator. It flips every bit (the 1s and 0s that make up a number) of a number. Each 0 becomes 1, and each 1 becomes 0.
For an int, the result is -(x + 1), because of the way computers store negative numbers. This is why compl 6 is -7.
Related Pages
Read more about operators in our C++ Operators Tutorial.