+ 1
Can someone tell me why ~0 is -1 in c language
#include <stdio.h> int main() { int n=~0; printf("%d",n); return 0; } Why output is -1
1 ответ
+ 2
https://www.sololearn.com/learn/4076/?ref=app
The bitwise complement operator inverses the sign of the given operand, then subtract the given operand's value by one. You will find it to be more clearly noticeable had you given it a non zero operand, as shown in the snippet below 👇
#include <stdio.h>
int main()
{
puts("Value\tInverted");
for(int num = -10; num < 11; num++)
{
printf("%d\t %d\n", num, ~num);
}
}