What's the difference between a boolean literal and a boolean value?

后端 未结 3 1467
醉酒成梦
醉酒成梦 2021-01-03 06:51

I can\'t seem to find a clear explanation as to what the difference is between these two. I\'d also like to point out that I don\'t really understand the difference between

3条回答
  •  梦毁少年i
    2021-01-03 07:29

    Values are expressions that can't be evaluated any longer. That means, these are values:

    • x
    • 123
    • true
    • "asdqwe"

    Now, literals are fixed value expressions. From the above list, the following are literals:

    • 123
    • true
    • "asdqwe"

    So, x has a value but not fixed.

    Answering the main question, booleans can only have two literals: false and true, and every boolean variable is a boolean value.

    You will see this in college in a compilers or computer semantics course, but the wikipedia pages linked here are very good if you still don't understand the difference.

提交回复
热议问题