Primitive data types
Every variable has both a name and a type. The type defines what kind of data can be stored in the variable. Typically, a language will have some built-in types, called primitive or basic types, to handle a single value.
Primitive types can be divided into two categories—Boolean and numeric—which we will look at next.
Boolean type
In Chapter 1, Introduction to Computer Programs, we talked about George Bool and his Boolean algebra. This defined how we can combine values of true
and false
with and
, or
, and not
. To be able to use these values in our programs, we have a type that is named after Bool, called Boolean. A variable that uses this type can only have one of two values—true
or false
. For languages that have these types, we use the actual true
and false
words.
Languages that have this type either call it Boolean
or just bool
.
Numeric type
Numeric types fall into one of two categories—integer types and floating...