What is the purpose of “int mask = ~0;”?
I saw the following line of code here in C. int mask = ~0; I have printed the value of mask in C and C++. It always prints -1 . So I do have some questions: Why assigning value ~0 to the mask variable? What is the purpose of ~0 ? Can we use -1 instead of ~0 ? It's a portable way to set all the binary bits in an integer to 1 bits without having to know how many bits are in the integer on the current architecture. C and C++ allow 3 different signed integer formats: sign-magnitude, one's complement and two's complement ~0 will produce all-one bits regardless of the sign format the system uses. So