1. Introduction
In this tutorial, we’ll talk about data types, the most fundamental and widely used categorization of data, and data structures, a collection of data types. Mainly, we’ll walk through their differences and introduce the most common instances for each case.
2. Data Type
Almost every programming language handles the concept of data type explicitly and includes almost the same basic data types. A data type is a classification or grouping of data.
In programming, a specific data type assignment helps the compiler to select an efficient and proper machine representation. Therefore, the declaration of a data type is a sort of specification or guidance exchanged between the developer and the computer in which the first one instructs the compiler to bind a certain part of the memory corresponding to the declared data type. This sort of classification of data is constructed for a variety of purposes, including resemblance, efficiency, or performance.
2.1. Common Data Types
The most common data types are integers (int), floating points (float), and characters (char). The first two correspond to numeric data types, without and with fractions, respectively. Character data type corresponds to character data of fixed length. Also, there exist sequences of digits and characters that are called strings (str). Booleans (bool) are binary data types that can hold one of two possible values: 0 (False) and 1 (True).
The declaration of different data types:
int a = 42;
float b = 0.42;
char c = 'C';
char d[]="42 is a great number";
bool flag = true;
3. Data Structure
A data structure, a group of data types, is a specific format and collection of data that may be executed using a certain set of operations for managing, accessing, processing, deleting, and storing data. There are various simple or complex forms of data structures, all of which are intended to organize information for a particular purpose. Data structures play a vital role in most real-world applications.
3.1. Common Data Structures
The most common data structures are Stacks and Queues, both representing container objects in which data is inserted and removed, according to the last-in-first-out (LIFO) and the first-in-first-out (FIFO) principle, respectively. The different logic between a Stack and a Queue is shown in the diagrams below:
Moreover, there are Linked Lists, which consist of connected nodes that also include a data field with some specific properties, and Binary Trees, which illustrate connected nodes with a hierarchical tree structure.
4. Differences Between Data Type and Data Structure
The main difference between data types and data structures:
Data Type
Data Structure
Single variable with a specific data form
Several forms of data types
Int, Float, Char, Strings Bools
Stacks, Queues, Trees, Lists
No algorithmic time complexity
Algorithmic time complexity
Direct assignment of value
Operations for entering data
Abstract Programming
Concrete Programming
5. Conclusion
In this article, we walked through data types and data structures and mainly covered their definitions, along with their fundamental differences. We also discussed the basic examples of a data type and a data structure.