- 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
- Integer: used to represent whole numbers, either positive or negative
We can declare variables as follows:
Python | Java | Visual Basic | |
Syntax | variable_name = value | data_type variable_name; | Dim variable_name As data_type |
Example | x = 5 | int x | Dim x As Integer |
It is important to choose the correct data type for a given situation to ensure accuracy and efficiency in the program.