Understand and use basic data types

Resources | Subject Notes | Computer Science

Basic Data Types - IGCSE Computer Science

Basic Data Types

In computer programming, data types define the kind of value a variable can hold. Understanding data types is fundamental for writing correct and efficient programs. This section explores the core basic data types used in introductory programming.

1. Integer (Integer)

Integers represent whole numbers – numbers without any fractional or decimal parts. They can be positive, negative, or zero.

  • Examples: -5, 0, 10, 1000
  • In programming, integers are typically stored using a fixed number of bits (e.g., 8-bit, 16-bit, 32-bit), which determines the range of values they can represent.

2. Floating-Point Number (Float)

Floating-point numbers represent numbers with decimal points. They can include fractional parts.

  • Examples: 3.14, -2.5, 0.0, 1.0
  • Floats are typically stored using a format that allows for a wide range of values, but with limited precision due to the way they are represented in binary.

3. Character (Character)

Characters represent a single letter, number, symbol, or punctuation mark.

  • Examples: 'A', '7', '$', ' ' (space)
  • Characters are typically stored using a character encoding system like ASCII or Unicode.

4. String (String)

Strings represent a sequence of characters. They are used to store text.

  • Examples: "Hello", 'IGCSE', "123 Main Street"
  • Strings are stored as a series of characters.

Data Type Table

Data Type Description Examples Typical Storage
Integer Whole numbers (positive, negative, zero). -5, 0, 10, 100 Fixed number of bits (e.g., 8-bit, 32-bit)
Float Numbers with decimal points. 3.14, -2.5, 0.0, 1.0 Floating-point format
Character Single letter, number, symbol, or punctuation mark. 'A', '7', '$', ' ' Character encoding (e.g., ASCII, Unicode)
String Sequence of characters (text). "Hello", 'IGCSE', "123 Main Street" Series of characters

Understanding these basic data types is crucial for choosing the appropriate data type for variables in your programs. This ensures that data is stored and processed correctly.