Home >Backend Development >C++ >The meaning of ~ in c language
~ is a logical NOT operator in C language, which performs a bit flip operation: if the expression is 0, it returns 1; if it is 1, it returns 0. Uses include: bit masking, bitwise negation, and logical negation.
The meaning of ~ in C language
In C language, the ~
symbol is A logical NOT operator. It performs a bit flip operation on a given expression, changing all bits in the expression from 0 to 1, or from 1 to 0.
Specifically, it does the following:
For example:
<code class="c">int x = 5; int y = ~x; printf("%d\n", y); // 输出:-6 int a = 0; int b = ~a; printf("%d\n", b); // 输出:1</code>
Usage:
~
operator is usually used The following scenarios:
The above is the detailed content of The meaning of ~ in c language. For more information, please follow other related articles on the PHP Chinese website!