Data types specify the type of data that you work with in a programme. The data type defines the size of memory needed to store the data and the kinds of operations that can be performed on the data.
The best way to understand what a data type is – is by looking at examples of data types.Â
A string variable can be seen as a ‘string’ of characters or a sequence of characters. It can contain many characters, as long as it is surrounded by “double quotation marks“.
If you were to forget the double quotation marks, you would get an error (shown by the red underline).
A char (short for character) can store unicode or single characters like ‘A’. This means that it can store values with only one letter or symbol.
Â
When using a char in code, you need to put your value in single quotes, like ‘B’ or ‘d’.
If you were to add more than one character or forget the single quotation marks in a char, you would get an error.Â
An int (short for integer) can store both positive and negative numbers.
An integer value takes up the memory space of 4 bytes. It can only store numbers.Â
Â
If we were to use letters in an int variable, we would get an error.Â
A double can store decimal values. It takes up the memory space of 8 bytes. You need to use a full stop (.) to create the decimal and not a comma (,).
If we were to use a comma to create our decimal, we would get an error.Â
A bool (short for boolean) can only store values as true or false. This takes up the memory space of 2 bytes.Â
A boolean can only take a true or false value. If we were to use “yes” or “no” as a value, we would get an error.Â
Good job – you know about data types now. But that’s just scratching the surface of programming.Â
Next up – let’s learn about variables and constants.Â
Click here to access the next topic if the “next topic” button isn’t working for you.Â