Unit content
Data types
A data type groups values that share a representation or a set of meaningful operations.
Typical types include integers, floating-point numbers, Boolean values and strings.
Operations depend on type
The same symbol can mean different operations for different types. Adding two numbers may perform arithmetic, while combining two strings may concatenate text.
A type therefore helps answer questions such as:
- which values are possible;
- which operations are allowed;
- how values are represented or checked.
Conversion
Sometimes a value must be converted from one type to another. Converting the text
"42"
to an integer produces a numerical value that can participate in arithmetic.
Conversions can fail or lose information. Converting a fractional floating-point value to an integer, for example, may discard the fractional part according to the language's rules.
Static and dynamic typing
In a statically typed system, many type relationships are checked before execution. In a dynamically typed system, values carry types that are checked primarily while the program runs.
These approaches differ in when and how errors are detected, but both rely on the same underlying idea: not every sequence of bits or program value supports every operation.