A data type refers to a collection of values that share a similar feature and therefore contain instructions, methods and abilities that those values can operate within. It organizes your code and its values so that you’re able to properly use the values.
Info
Although there are common data types across languages, how they are used and named may be completely different. Lower level languages, like C for example, may have more defined versions such as
longvsshortto allow for more precise memory control.
Table
Below is a table of common data types:
| Data type | Example | Example language | Description |
|---|---|---|---|
short | short x = 1 | C++, C# | 16 bits/ 2 bytes, refers to an integer within the range of -32,768 to 32,767 |
long | long x = 1 | C++, C# | 32 bits/ 4 bytes, refers to an integer within the range of -2,147,483,648 to 2,147,483,647 |
long long | long long x = 1 | C++ | 64 bits/ 8 bytes, refers to an integer within the range of −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
int | int | C, C++, C# | Standard 16 bits, refers to an integer. |
| arbitrary precision integers | x:int = 1 | Python, Haskell, Lisp, | Also known as infinite precision integers or bignums, these integer data types have no set range like the others defined above. |
bool | bool x = 1 | C, C++, C# | Booleans have values either “1” or “0” - or a “true” and “false” respectively. |
| unsigned | unsigned short x = 1 | C, C++ | Usually prefixing another integer data type, unsigned integers are always positive - therefore increasing the range of positive numbers. |
float | float x = 1.5 | C, C++, C# | Floating points refer to numbers with decimals to high precision. |
char | chat x = 'a' | C, C++ | Represents a single character. |
string | msg:str = "hi!" | Python | Represents a string of characters. |
Data structures:
| Data structure | Example | Description |
|---|---|---|
| Array | C++: int[] = [1, 2, 3] Python: python_list = [1, 2, 3] | Also known as a list, it represents a collection of values. Each value can be retrieved from the list by the ‘index’, which is the position of an element in the array usually counting up from 0. |
| Linked list | example | Similar to an array, but contains a sequence of values. |
| Record | Python: my_tuple = (x, 2)C++: struct{string x; int num;} my_structure | Also known as a struct or a tuple, a record can be displayed like a ‘coordinate’, or in a database - a ‘row’ and its subsequent ‘field’. |
| Hash tables | Python: my_dict = {"name": "Jay"}Dart: Map<String, String> my_map = {"name": "Jay"} | Also known as a map or a dictionary, a hash table is a complex data structure built with ‘key: value’ pairs, meaning you can retrieve the value by calling its key (in the example, my_dict["name"] will retrieve Jay). |
| Graphs | examples![]() | Visually, a graph by itself isn’t displayed like a graph in code. It will done with adjacency matrixes, lists, etc. Graphs consists of ‘nodes’ (vertices) connected by ‘edges’, which can be used to map relationships between objects. |
| Stacks | Python: my_stack = [1, 2, 3]my_stack.pop() # pops out 3 from list | Stacks are lists following the principle of “last-in, first-out”. Think of a stack of dirty dishes, the most recent dish to go on top will be cleaned first. |
| Queue | Python:my_queue = [1, 2, 3]my_queue.pop(0)OR my_queue = deque([1, 2, 3])my_queue.popleft() | Queues are lists following the principle of “first-in, first-out”. Think of an actual queue, the person who gets in the queue first will get out of the queue first. |
