Skip to content

Data types

To understand data types, you need to understand that there are two ‘types’ of programming languages:

  • statically typed languages
  • dynamically typed languages

Dynamically typed languages don’t require you to give a variable a data type when you create it. Instead, types don’t really exist and the language just figures out how best to store the variable based on the value you give it.

An example of a dynamically typed language is Python. We can give any variable data of any type:

x = 5 # x is an integer
x = "hello" # now x is a string

Statically typed languages (such as C) do require you to give a variable a data type when you create it. This means that the variable can only hold data of that type.

For example, in C we can create an integer variable like this:

int x = 5; // x is an integer

If we try to give x a string value later on, we’ll get an error:

x = "hello"; // Error: cannot convert char* to int

These are some important data types that we’ll cover in future chapters!

Data TypeDescriptionExample Values
intInteger (whole) numbers1, -5, 42
floatFloating-point (decimal) numbers3.14, -0.001, 2.0
stringText, really an array of chars”hello world”, “123”
boolBoolean values (true or false)true, false
charSingle character’a’, ‘Z’, ‘1’
arrayCollection of values of the same type[1, 2, 3], [“a”, “b”]
objectAn instance of a structstruct Person {char* name; int age;}