Chapter 2 - Data and Data Processing
Chapter 2 Part 2 Data types
Part 2: Data types
A data type is a classification that specifies what kind of data a variable or object can store. Data types determine the possible values that a variable can assume and the operations that can be performed on these values.
In other words:
- Numbers can be integers or decimal numbers and mathematical operations can be applied to them.
- Characters can be strung together to form words, for example.
Examples of data types are:
- Integers: Store integers, e.g. 1, 2, 3.
- Floating point numbers (float): Store decimal numbers, e.g. 3.14, 2.718.
- Character strings (String): Save text, e.g. "Hello", "World".
- Boolean values (Boolean): Store truth values, e.g. true or false.
Elementary data types, also known as simple data types or primitive data types, can only accept one value from the corresponding value range.
Complex data types
Complex data types are data types that are composed of simpler data types. They make it possible to store and process structured data. Complex data types can combine several values and different types of data in a single unit. They are therefore also referred to as data structures.
Examples of data types
Elementary data types | Complex data types |
Whole numbers | Arrays |
Are an extension of the natural numbers by negative numbers: ..., -3, -2, -1, 0, 1, 2, 3, ... | A collection of elements of the same data type that are addressed via indices. |
Fixed point numbers | Structures |
Numbers that have a fixed number of digits before and after the decimal point | A collection of fields that can contain different data types. |
Enumeration types | Classes |
Are variables with a finite set of values, e.g. color with the values: blue, green, red, yellow) | Similar to structures, but with additional functions such as inheritance and methods. |
Boolean | Lists |
Used to represent logical truth values: true or false | An organized collection of elements that can grow and shrink dynamically. |
Character | Dictonaries |
Are basic elements of a language, e.g. A, B, C, .... | A collection of key-value pairs where each key is unique. |
Pointer | |
Pointers are references to any other data type, e.g. the address of another data element |
Data structures
Data structures are used in almost all areas of computer science and software development. They help to organize and process data efficiently, which can significantly improve the performance of programs. For example:
- Search algorithms use trees and hash tables to enable fast search operations.
- Sorting algorithms use arrays and linked lists to arrange data in a specific order.
- Graphs are used to model networks and solve problems such as shortest path finding.
- Stacks and queues are essential for managing tasks and controlling the program flow.