im doing a research on boolean.
The Boolean data type uses an integer storage code. How is this useful to a
programmer?
C++ Boolean s
Started by b3hr0uz, Apr 20 2009 01:12 PM
5 replies to this topic
#1
Posted 20 April 2009 - 01:12 PM
|
|
|
#2
Posted 20 April 2009 - 04:29 PM
I'm not sure I understand your question. A boolean data type is a good choice if you want to store a variable that can only have 2 values (true or false).
#3
Posted 20 April 2009 - 04:37 PM
brownhead said:
I'm not sure I understand your question. A boolean data type is a good choice if you want to store a variable that can only have 2 values (true or false).
what i mean is,
why do programmers use a boolean
#4
Posted 20 April 2009 - 05:01 PM
Well its for the sake of simplicity and readability of your code. Using a boolean would be the same as using an integer, however, using an integer is less concise.
Perhaps an example will help me explain this better
Lets say we have the function isReady, that returns an integer. How does someone know what return value means true (it is ready) or false (it is not ready). It could be 1 means true, or 0 means true, or 1992 means true. Its a bit confusing unless your the one who wrote the function. So this would be a case in which you would use boolean values, solving the confusion.
This is just one way that boolean values may be used, but I think its a decent example.
Perhaps an example will help me explain this better
Lets say we have the function isReady, that returns an integer. How does someone know what return value means true (it is ready) or false (it is not ready). It could be 1 means true, or 0 means true, or 1992 means true. Its a bit confusing unless your the one who wrote the function. So this would be a case in which you would use boolean values, solving the confusion.
This is just one way that boolean values may be used, but I think its a decent example.
#5
Posted 21 April 2009 - 06:41 AM
In C, the boolean type didn't exist. As a result, integer values were used, with 0=false, other=true. For converting the other way, false=0, true=1. Unfortunately, the result was that different people would create aliases for TRUE and FALSE using macros. They varied from programmer to programmer, with various cases being used.
C++ maintains the implicit conversion rules from C programming, and simply standardized true and false as the values a boolean could take.
C++ maintains the implicit conversion rules from C programming, and simply standardized true and false as the values a boolean could take.
#6
Posted 30 April 2009 - 06:39 AM
Good answer


Sign In
Create Account

Back to top









