Boolean

Boolean is a data type that has only two possible values: true and false.

Because an individual bit also has just two possible values (0 and 1), it's tempting to think that a boolean is stored in just 1 bit. But in practice, booleans often take up a whole byte (8 bits). This is because a byte is usually the basic addressable unit in a computer. In other words, usually the computer doesn't grab individual bits in memory—instead it grabs "chunks" of 8 bits or more at a time.

Sometimes booleans take up as much space as an integer, which is often 32 or 64 bits in modern computers. In fact, in some languages, like Python, booleans are subclasses of integers.

What's next?

If you're ready to start applying these concepts to some problems, check out our mock coding interview questions.

They mimic a real interview by offering hints when you're stuck or you're missing an optimization.

Try some questions now

. . .