Data Types CS Thinking Example 1
Follow the full solution, then compare it with the other examples linked below.
Example 1
easyClassify each value into its data type: (a) 42, (b) 'Hello', (c) 3.14, (d) TRUE.
Solution
- 1 Step 1: 42 is a whole number with no decimal point โ this is an integer.
- 2 Step 2: 'Hello' is text enclosed in quotes โ this is a string.
- 3 Step 3: 3.14 has a decimal part โ this is a float (real number). TRUE is a logical value โ this is a boolean.
Answer
(a) Integer, (b) String, (c) Float/Real, (d) Boolean.
Data types define what kind of value a variable holds and what operations can be performed on it. The four fundamental types are integer, float, string, and boolean.
About Data Types
Categories that classify data values and determine which operations can validly be performed on them. Common data types include integers, floating-point numbers, strings, booleans, and arrays, each with its own set of permitted operations.
Learn more about Data Types โMore Data Types Examples
Example 2 medium
A program reads user input as a string '25'. What happens if you try to calculate '25' + 10 without
Example 3 mediumFor each scenario, choose the most appropriate data type: (a) a student's name, (b) number of studen
Example 4 hardA program stores prices as integers in pence (e.g., 499 for ยฃ4.99) rather than as floats. Explain tw