0

I recently have been reading a tuition book in C++, the question was under a chapter discussing Boolean operators. The question that confused me was as follows:

  1. Which of the following is true?
    • A. 1
    • B. 66
    • C. .1
    • D. -1
    • E. All of the above

The answer itself is E according to the paper however, from a newbie perspective like myself, I assumed that A was the answer as a true value is stored as a 1 whereas a false value was stored as a 0? So why would the answer be all of the above?

Ulivax
  • 9
  • 1
  • 8
  • 2
    It's a poor question but they probably mean: which of these would result in `true` after being converted to `bool` – M.M Aug 18 '18 at 14:46
  • 1
    Any value other than `0` is considered as `true` in C++. – haccks Aug 18 '18 at 14:46
  • I thought that it asks *which of the following answer is true (correct)?*. It took me a while to understand that the question actually asks *which of the following evaluates to true?* [In C++ what causes an assignment to evaluate as true or false when used in a control structure?](https://stackoverflow.com/q/2003895/995714), [What is the boolean value of integers other than 0 or 1?](https://stackoverflow.com/q/27024044/995714) – phuclv Aug 18 '18 at 14:59

1 Answers1

1

Any value that is not equal to zero is considered true. So the answer to the question is E since none of the listed values are zero.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70