Programming languages have several primitive data types to store and represent data. Types define the set of values a variable of type can take. Languages can be divided into several categories:
- Strongly/weakly typed
- Weakly-typed languages convert between unrelated types implicitly.
- Strongly-typed languages don’t allow implicit conversions.
- Statically/dynamically typed
- Statically-typed languages do type checking (verifying/enforcing constraints) at compile-time.
- Dynamically-typed languages do this at runtime.
Type systems
Common types
A brief list of common types in programming languages:
- Integers
int
, 32 bitsshort
, 16 bitslong
, 32 bitslong long
, 64 bits
- Floating-point number
float
, 32 bits, 7 digit precisiondouble
, 64 bits, 15 digit precision (“double precision”)long double
, 19 digit precision
- Text
char
, 8 bits, in single quotesstring
, for a size-varying string, in double quotes
- Boolean values,
bool
(true, false) - And the
void
type
Note that the exact bit/byte length for a type will vary from machine to machine. Often some types are defined such that we can use a certain bit length, i.e., int8_t
(or i8
) for an 8-int signed integer.
Variant types
A composite data type is constructed with multiple primitive data types (listed above). In C/C++/Rust, composite types are implemented with the struct keyword.