Jayesh Jayesh - 6 months ago 39
C Question

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
in C and C++. It always prints

So, I have some questions:

  • Why assigning value
    to the mask variable?

  • What is the purpose of

  • Can we use
    instead of

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download