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

前端 未结 6 626
春和景丽
春和景丽 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:14

    Loooong ago this was how you saved memory on extremely limited equipment such as the 1K ZX 80 or ZX 81 computer. In BASIC, you would

    Let X = NOT PI
    

    rather than

    LET X = 0
    

    Since numbers were stored as 4 byte floating points, the latter takes 2 bytes more than the first NOT PI alternative, where each of NOT and PI takes up a single byte.

提交回复
热议问题