Data Types
-
A data type is a classification of data into groups according to the kind of data they represent
-
Computers use different data types to represent different types of data in a program
-
The basic data types include:
-
Integer: used to represent whole numbers, either positive or negative
-
Examples: 10, -5, 0
-
-
Real: used to represent numbers with a fractional part, either positive or negative
-
Examples: 3.14, -2.5, 0.0
-
-
Char: used to represent a single character such as a letter, digit or symbol
-
Examples: 'a', 'B', '5', '$'
-
-
String: used to represent a sequence of characters
-
Examples: "Hello World", "1234", "@#$%
-
-
Boolean: used to represent true or false values
-
Examples: True, False
-
-
We can declare variables as follows:
|
|
|
|
Syntax |
variable_name = value |
data_type variable_name; |
Dim variable_name As data_type |
Example |
|
|
|
It is important to choose the correct data type for a given situation to ensure accuracy and efficiency in the program.
Worked example
Name and describe the most appropriate programming data type for each of the examples of data given. Each data type must be different
[6]
Data: 83
Data type name: Integer [1]
Data type description: The number is a whole number [1]
Data: [email protected]
Data type name: String [1]
Data type description: It is a group of characters [1]
Data: True
Data type name: Boolean [1]
Data type description: The value is True (or could be False) [1]