Hi everybody, I was wondering if you could help me with this ~ operator.
I just tried the following simple program in my Turbo C;
Code:
int main() {
unsigned short int i = ~0;
printf("%d", i);
return 0;
}
i expected the program to return the maximum value that can be stored i.e: 65535 but the o/p produced was -1. Also, when i tried the same program in codepad.org (online compiler), the o/p was 65535. And in both my PC and the online version the ~ doesn't seem to be producing the expected o/p for other integer types such as "int", "long" etc.
Can you someone please tell me if i'm doing anything wrong? Thanks