+ 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

26th Jun 2020, 3:28 AM
Noman
Noman - avatar
1 Odpowiedź
+ 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); } }
26th Jun 2020, 4:22 AM
Ipang