What is the purpose of “int mask = ~0;”?

前端 未结 6 659
春和景丽
春和景丽 2020-12-29 18:30

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

6条回答
  •  半阙折子戏
    2020-12-29 19:12

    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.

提交回复
热议问题