Data Types (in computer programs)
In computer programming, data types are the attributes that specify the type of data that a data structure can hold.
We need to declare a data type for variables and arrays.
Why bother?
It’s important to specify the right data type for your data structures because the program needs to know what type of values an object can store and which operations can be successfully performed using it.
Failure to use the correct data type may result in you losing the ability to perform sorts or calculations using the data.
Common Data Types
The names that we give to certain data types can change from one programming language to another, but here is a list found in many:
Data Type | Description | Example Data |
---|---|---|
Integer | Whole numbers | 56 |
Date | Date | 12/12/2000 |
Boolean | Logical True/False | TRUE |
String | Alphanumeric characters, text | “I am a string” |
Real | Numbers that may have decimal places | 15.7 |
Char | Single character | ‘B’ |
Please note the use of quotation marks to indicate a string of text or single character. String values without quotation marks will be mistaken for variables.
Also note the lack of quotation marks for the boolean value of TRUE. This is because it is a logical state of being, not the storage of the string “TRUE”.