## Data Types

Programming languages use data types to allocate memory and enforce data integrity. They also reveal the nature of a language.

Would you multiply the words SpongeBob times Squarepants? It makes more sense to multiply the number 5 times 33, doesn’t it?

Programming languages avoid this kind of error by using data types. A person’s first name and last name are identified as strings while the numbers 5 and 33 are identified as integers, a fancy word for numbers. Data types help languages process data efficiently with as few preventable errors as possible.

### Common Data Types

Here are the most common data types you encounter with all programming languages. A language may use a different name but the data type is the same as other languages.

Data Type Description
boolean A boolean is true or false, yes or no.
floating Fractional numbers often expressed as decimals. Think 1.23.
integer Whole numbers which may or may not include negative numbers.
pointer A value that refers to (points to) another value stored in a specific location, usually in computer memory.
string Alphanumeric characters as well as numbers not treated or processed as integers.

When you learn any programming language, pay attention to how the language handles these data types. Often the available data types define the language. For example, the Erlang language doesn’t have booleans but it does have atoms which are true or false.

Of course, this is an extremely simplified description of data types. There are complex data types, for example, arrays which are collections of nested data often organized by keys where each key has a specific value. This article only introduces you to key concepts, not the gory details you learn as you code in a new language.

Each data type also has a size, measured in bytes, which the programming language uses to allocate memory as the application runs. If you don’t know, or remember, a byte is the smallest addressable space in computer memory. A byte is eight bits in length where each bit is a binary digit of either 0 or 1. Binary digit equals bit, if you get it? So 2 bytes is 16 bits, or binary digits, in length and 4 bytes is 32 binary digits in length. But most people speak in terms of bytes, not bits.

When you learn any programming language, pay attention to how the language handles these data types. Often the available data types defines the language. For example, Erlang doesn’t have booleans but it does have atoms which are true or false.

### C

The C language has a rich set of data types, not only the basics of booleans, integers, and strings but also points, floating, void, and so on. C also has short integers and long integers which differ based on their size. C also has arrays, pointers, and other constructed data types.

### Erlang

In the Erlang language, any data within a data type is called a term. So the word house and 551 are both called terms. The Number data types are integers and floats. What other languages call a boolean Erlang calls an atom with a value that is true or false. While strings are used in Erlang, it is not a data type.

The language also has a data type called fun which is a function treated as an object. The same way you pass a number from one function to another, in Erlang you use a fun to pass a function as an object from one function to another.

### PHP

The PHP language supports eight data types: boolean, integer, float, string, array, object, resource, and null. As with some other languages, you can check the data type of a value to ensure code only runs if a value is the correct type. So you can avoid the problem of accidentally multiplying Fred times Flintstone.

### Ruby

The way Ruby handles data types is a bit different from other languages. The method is duck typing which means any function assumes the values it works on are the correct values. So a class called Duck with a walk function and a quack function would not confirm the correct values are passed to it before it runs the quack or walk function. If the values are the wrong type, an error occurs. The burden is on the programmer to ensure only correct values are passed through and errors alert the programmer to fix any problems.

In other words, Ruby uses strings, integers, booleans, arrays, and other data types found in other languages. However, handling the data types is more loose and data types are enforced through run-time errors.

#### Data types

https://press.rebus.community/programmingfundamentals/chapter/data-types/

#### What are Data Types?

https://amplitude.com/blog/data-types

#### Data types

https://en.wikipedia.org/wiki/Data_type

#### What is Erlang?

https://www.erlang.org/faq/introduction.html

#### Erlang Programming Language

https://en.wikipedia.org/wiki/Erlang_(programming_language)

#### Introduction to Erlang

https://serokell.io/blog/introduction-to-erlang

#### What is Boolean Data Type?

https://en.wikipedia.org/wiki/Boolean_data_type

#### String

https://en.wikipedia.org/wiki/Boolean_data_type

#### Composite Data Type

https://en.wikipedia.org/wiki/Composite_data_type

#### Array data structure

https://en.wikipedia.org/wiki/Array_data_structure

#### Data type facts for kids

https://kids.kiddle.co/Data_type

#### Data type

https://wiki.kidzsearch.com/wiki/Data_type

#### A math dictionary for kids

http://www.amathsdictionaryforkids.com/qr/d/dataTypes.html

## Author

• Tim is an award-winning writer and technologist who enjoys teaching tech to non-technical people. He has many years experience with web sites and applications in business, technical, and creative roles. He and his wife have two kids, now teenagers, who are mad about video games.

### Also In The October 2022 Issue

A collection fo gift ideas for the holidays and any time of year!

Begin your 3D design journey with Blender!

Technology is here to stay, so we should talk about how to be safe when using it.

Programming languages use data types to allocate memory and enforce data integrity.

Dive to new depths with this Minecraft mod!

Improve your encryption skills with Unicode!

Meet a computer that makes fantasy a reality!

Experience a new level of futuristic luxury with your own robot butler.

Find out how your country compares to the rest of the world in CS education

Learn how digitization is being used to help preserve the languages of Indigenous peoples

Find out how social media is being used to build a more peaceful world

Check out what happens when you combine 3D printing with Auxetic geometries!

Collection of interesting stories about technology from October 2022