Integer: Represents whole numbers without any fractional or decimal components. These can be positive, negative, or zero (e.g., , , ).
Real (or Float): Used for numbers that require fractional precision. These are essential for scientific calculations or financial data where decimals are necessary (e.g., , ).
Char: Short for 'Character', this type stores exactly one alphanumeric symbol, such as a letter, digit, or punctuation mark. It is usually enclosed in single quotes in code (e.g., 'A', '7', '$').
String: A collection or sequence of characters treated as a single block of text. Strings can contain letters, numbers, and symbols, and are typically enclosed in double quotes (e.g., "User123").
Boolean: The simplest data type, representing logical states. It can only hold one of two values: True or False.
Date: A specialized type used to store calendar information, allowing for date-based arithmetic like calculating the number of days between two events.
| Feature | Char | String |
|---|---|---|
| Length | Exactly 1 character | 0 to many characters |
| Memory | Fixed/Small | Variable/Larger |
| Usage | Single keys, initials | Names, sentences, IDs |
Context is Key: When asked to choose a data type for a scenario, look for keywords. If the data involves money, always choose Real because currency requires decimal places.
Boolean Efficiency: Use Boolean types for any 'Yes/No' or 'On/Off' scenarios. It is more memory-efficient and logically clearer than using an Integer (0 or 1) or a String ("Yes").
Pseudocode Precision: Ensure you use the exact keywords required by the syllabus (e.g., INTEGER instead of int, REAL instead of float) to avoid losing marks on syntax.
Validation: Always check if the data type supports the required operations. If you need to calculate an average, the result must be stored in a Real variable, even if the inputs are Integers.
The 'Number' String: Students often assume that because a phone number or zip code consists of digits, it should be an Integer. However, since no math is performed on these and they may start with leading zeros, they should be stored as Strings.
Case Sensitivity: In Boolean logic, True is not the same as the string "True". One is a logical state used in conditions, while the other is just text.
Character Limits: Forgetting that a Char can only hold one symbol. If you try to store "AB" in a Char variable, the program will likely crash or truncate the data.