Each variableA memory location within a computer program where values are stored. must have a data type. The data type determines what type of value the variable will hold.
Data type
Purpose
Example
Integer
Whole numbers
27
Float
Decimal numbers
27.5
Character
A single alphanumeric character
A
String
One or more alphanumeric characters
ABC
Boolean
TRUE/FALSE
TRUE
Data type
Integer
Purpose
Whole numbers
Example
27
Data type
Float
Purpose
Decimal numbers
Example
27.5
Data type
Character
Purpose
A single alphanumeric character
Example
A
Data type
String
Purpose
One or more alphanumeric characters
Example
ABC
Data type
Boolean
Purpose
TRUE/FALSE
Example
TRUE
Different data types have limitations:
integers and floats cannot be concatenated, ie joined together
numbers held in strings cannot be subject to mathematical operations
Casting
Sometimes a programmer needs to change the data type of a variable. For example, an integer may need to be converted to a string in order to be displayed as part of a message. This process is known as casting. The following examples convert a string to an integer and an integer to a string: