Has TRUE always had a non-zero value?

前端 未结 22 1041
予麋鹿
予麋鹿 2020-12-31 01:38

I have a co-worker that maintains that TRUE used to be defined as 0 and all other values were FALSE. I could swear that every language I\'ve worked with, if you could even

22条回答
  •  醉酒成梦
    2020-12-31 01:58

    In the C language, before C++, there was no such thing as a boolean. Conditionals were done by testing ints. Zero meant false and any non-zero meant true. So you could write

    if (2) {
      alwaysDoThis();
    } else {
      neverDothis();
    }
    

    Fortunately C++ allowed a dedicated boolean type.

提交回复
热议问题